Tuesday, October 21, 2014

How do you connect to a sql server database using C#

Posted by Gnani Palepu  |  No comments


 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  

 using System;  
   using System.Data.SqlClient;  
   namespace ConsoleCSharp  
   {  
   /// <summary>  
   /// Summary description for Class1.  
   /// </summary>  
   class DataReader_SQL  
   {  
   /// <summary>  
   /// The main entry point for the application.  
   /// </summary>  
   [STAThread]  
   static void Main(string[] args)  
   {  
   //  
   // TODO: Add code to start application here  
   //  
   try  
   {  
   SqlConnection thisConnection = new SqlConnection(@"Network Library=DBMSSOCN;Data Source=192.168.0.100,1433;database=Northwind;User id=Paladine;Password=;");  
   thisConnection.Open();  
   SqlCommand thisCommand = thisConnection.CreateCommand();  
   thisCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers";  
   SqlDataReader thisReader = thisCommand.ExecuteReader();  
   while (thisReader.Read())  
   {  
   Console.WriteLine("\t{0}\t{1}", thisReader["CustomerID"], thisReader["CompanyName"]);  
   }  
   thisReader.Close();  
   thisConnection.Close();  
   }  
   catch (SqlException e)  
   {  
   Console.WriteLine(e.Message);  
   }  
   }  
   }  
   }  

 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  


6:22 AM Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top