Monday, August 8, 2011

Monday 8.8.11

using System;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Odbc;

namespace ConnectSqlServer
{
class Program
{
static void Main(string[] args)
{
//connect using .net data provider for SQl Server and integrated security
string sqlConnectString1 = @"Data Source=Alfred-PC\SQLExpress;" +
"Integrated Security=SSPI;Initial Catalog=AdventureWorks;";

using (SqlConnection connection = new SqlConnection(sqlConnectString1))
{
connection.Open();
//return some information about the server
Console.WriteLine("---.NET data provider for SQL Server" + " with Windows Authentication mode---");
Console.WriteLine("ConnectionString = {0}\n", sqlConnectString1);
Console.WriteLine("State = {0}", connection.State);
Console.WriteLine("DataSource = {0}", connection.DataSource);
Console.WriteLine("ServerVersion = {0}", connection.ServerVersion);
}

Console.WriteLine("--------------------------------------------------");

//connect using .NET data provider for SQL Server and SQL Server authentication
string sqlConnectString2 = @"Data Source=Alfred-PC\SQLExpress;" +
"User ID=sa;Password=china;Initial Catalog=AdventureWorks;";
using (SqlConnection connection = new SqlConnection(sqlConnectString2))
{
connection.Open();
//return some information about the server
Console.WriteLine("\n---.Net data provider for SQL Server " + "with SQL Server Authentication mode---");
Console.WriteLine("ConnectionString = {0}\n", sqlConnectString2);
Console.WriteLine("State = {0}", connection.State);
Console.WriteLine("DataSource = {0}", connection.DataSource);
Console.WriteLine("ServerVersion = {0}", connection.ServerVersion);
}

Console.WriteLine("--------------------------------------------------");

//connect using .NET data provider for OLE DB.
string oledbConnectString = @"Provider=SQLOLEDB;Data Source=Alfred-PC\SQLExpress;" +
"Initial Catalog=AdventureWorks;User Id=sa; Password=china;";

using (OleDbConnection connection = new OleDbConnection(oledbConnectString))
{
connection.Open();
//return some information about the server.
Console.WriteLine("\n---.NET data provider for OLE DB---");
Console.WriteLine("ConnectionString = {0}\n", oledbConnectString);
Console.WriteLine("State = {0}", connection.State);
Console.WriteLine("DataSource = {0}", connection.DataSource);
Console.WriteLine("ServerVersion = {0}", connection.ServerVersion);
}

Console.WriteLine("--------------------------------------------------");

//connect using .NET data provider for ODBC.
//(COULD NOT GET THIS ONE TO WORK)
string odbcConnectString = "Driver={SQL Native Client};" + @"Server=Alfred-PC\SQLexpress;Database=AdventureWorks;uid=sa;pwd=china;";

using (OdbcConnection connection = new OdbcConnection(odbcConnectString))
{
connection.Open();

//return some information about the server
Console.WriteLine("\n---.NET data provider for ODBC---");
Console.WriteLine("ConncetionString = {0}\n", odbcConnectString);
Console.WriteLine("State = {0}", connection.State);
Console.WriteLine("DataSource = {0}", connection.DataSource);
Console.WriteLine("ServerVersion = {0}", connection.ServerVersion);
}
}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string sqlText = "SELECT TOP 15 * FROM Person.Contact";
string connectString =
ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sqlText, connectString);
da.Fill(dt);
foreach (DataRow row in dt.Rows)

Response.Write( "ID" + " " + row["ContactID"] + " - " + row["LastName"] + ", " + row["FirstName"] + "
");
string sqlText2 = "SELECT TOP 15 * FROM HumanResources.Employee";
DataTable dt2 = new DataTable();
SqlDataAdapter da2 = new SqlDataAdapter(sqlText2, connectString);
da2.Fill(dt2);
foreach (DataRow row in dt2.Rows)
Response.Write(row["employeeID"] + "\n" + row["title"] + "
");
}
}


#include
int main(void)
{
char firstName[12] = {"Alfred"};
char lastName[12] = {"Jensen"};

printf("%s, %s \n", firstName, lastName);
printf("%s \n", firstName);
printf("%s \n", lastName);
printf("%s, %s \n", firstName, lastName);
}


#include
void jolly(void);//c function prototyping

int main(void)
{
jolly();
jolly();
jolly();
printf("Which nobody can deny!\n");
}

void jolly(void)
{
printf("For he's a jolly good fellow!\n");
}



/*rhodium.c your weight in rhodium */
#include
int main(void)
{
float weight;
float value;
printf("Are you worth your weight in rhodium?\n");
printf("Let's check it out.\n");
printf("Please enter your weight in pounds:");

//get inpput from the user
scanf("%f", &weight);
//assume rhodium is $770 per ounce
value = 770.0 * weight * 14.5833;
printf("Your weight in rhodium is worth $%.2f.\n", value);
printf("You are easily worth that! If rhodium prices drops, \n");
printf("eat more to maintain your value.");
}

No comments: