Which Namespaces Must Be Used to Connect to SQL Server with ADO.NET?

Posted by every_answer_gets_a_point on Stack Overflow See other posts from Stack Overflow or by every_answer_gets_a_point
Published on 2010-04-27T01:07:10Z Indexed on 2010/04/27 3:13 UTC
Read the original article Hit count: 192

Filed under:
|
|

i am using this example to connect c# to sql server. can you please tell me what i have to include in order to be able to use sqlconnection?

it must be something like: using Sqlconnection; ???

string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=""C:\SQL Server 2000 Sample Databases\NORTHWND.MDF"";Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection sqlCon = new SqlConnection(connectionString);
 sqlCon.Open();

string commandString = "SELECT * FROM Customers";
 SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
 SqlDataReader dataReader = sqlCmd.ExecuteReader();

while (dataReader.Read())
 {
   Console.WriteLine(String.Format("{0} {1}", dataReader["CompanyName"], dataReader["ContactName"]));
 }
 dataReader.Close();
 sqlCon.Close();

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server