Answer Posted / nitin kumar
Steps for 1. Using a SqlConnection
// Fully Commented Code
using System;
using System.Data;
using System.Data.SqlClient;
class SqlConnectionDemo
{
static void Main()
{
// 1. Instantiate the connection
SqlConnection conn = new SqlConnection(
"Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI");
SqlDataReader rdr = null;
try
{
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
SqlCommand cmd = new SqlCommand("select * from
Customers", conn);
//
// 4. Use the connection
//
// get query results
rdr = cmd.ExecuteReader();
// print the CustomerID of each record
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}
}
| Is This Answer Correct ? | 7 Yes | 0 No |
Post New Answer View All Answers
What is the maximum number of classes that can be contained in one dll file?
What is the difference between Classic ASP and ASP.Net?
Is asp.net mvc front end or backend? : Asp.Net MVC
Explain different types of validators in asp.net?
What are different types of authentication techniques that are used in connection strings to connect .net applications with microsoft sql server?
Describe the diffeerence between inline and code behind - which is best in a loosely coupled solution?
Explain the steps needed to be performed in order to create an animation in xaml?
What is enableviewstate in asp net?
How do cookies work?
i want to implement grid view value in paypal site. so how to create this code in asp.net with C#
What is the difference between ldap and active directory?
What is Dynamic Web and discuss its usage with the help of real life examples?
What are the asp.net server side objects?
What are the contents of cookie?
What is the function of new view engine in asp.net? : asp.net mvc