Saturday 30 April 2011

How To Create Sql Connection in C# and in Vb

Csharp

SqlConnection conn = new
SqlConnection("Data Source=.;Initial Catalog=Northwind;User ID=sa");
SqlCommand cmd = new
SqlCommand("Select * From Customers Where CustomerID = ’" +
eventArgument + "’", conn);
conn.Open();
SqlDataReader MyReader;
MyReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
string[] MyValues = new string[11];
String.Join("|", MyValues);//This is use to concate the array into string



Dim conn As SqlConnection = New _
SqlConnection("Data Source=.;Initial Catalog=Northwind;User ID=sa")
Dim cmd As SqlCommand = New _
SqlCommand("Select * From Customers Where CustomerID = ’" & _
eventArgument & "’", conn)
conn.Open()

No comments:

Post a Comment