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 are session objects?
Give a few examples of page life cycle events.
Differentiate between a page theme and a global theme?
What are validator? Name the validation controls in asp.net? How do you disable them?
What is the purpose of App_Code folder in ASP.NET? Why we this?
How can you make sure that web api returns json data only?
What kind of data we can store in viewstate?
Why mvc is faster than asp.net? : Asp.Net MVC
What is viewstate information stored?
what is AutoEventWireUp and what is the use of This property explain in details?
Web API uses which library for JSON serialization?
What is the server of asp.net?
What can we do with asp.net?
Define web.config in .net?
Explain how do you deploy your asp.net application?