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 _dopostback in asp net?
Dataset is the disconnected environment. suppose if you are binding records to gridview (disconnected environment) and you are making changes to the the grid but before updating the database if any other user modify the data, how will you avoid such problem?
What is a server cookie?
What is the request flow used for asp.net mvc framework? : asp.net mvc
Describe the differences between the lifecycles of Windows services and Standard EXE?
What are different types of authentication techniques that are used in connection strings to connect .net applications with microsoft sql server?
What does mvc represent in asp.net? : asp.net mvc
Differentiate between authentication and authorization.
How is it possible for .NET to support many languages?
Can we use html in asp.net?
Is sql backend or frontend?
Explain significance of routing? : asp.net mvc
What is asp.net futures?
What is asp.net and ado net?
What is cross page posting in asp net?