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
Which type if caching will be used if we want to cache the portion of a page instead of whole page?
Explain model, view and controller represent in an mvc application? : asp.net mvc
What is autopostback in asp net?
How will you load dynamic assembly?
Please brief not about xsd,xslt & xml?
Define application state variable and session state variable?
What is the difference between stored procedure vs function?
How can we Validate a Controls in ASP.NET page using JavaScript?
Why session is necessary in web application?
How can we apply themes to an asp.net application?
What are the versions of garbage collection?
What does a switch do?
What is routing in MVC?
How do I use response redirect?
Elaborate differentiation between ViewState and SessionState?