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 good practice to implement validations in aspx page?
What are the session variables?
what are the web form events available in asp.net?
What is state management react?
What is the difference between session and viewstate in asp.net?
What is the differences between a primary key and a unique key in sql server?
In early binding will the method invoked on com component will verify it?s existance in the system or not ?
List some of the important session state modes of asp.net.
Is sql backend or frontend?
Where sessions are stored in asp.net?
How to store checkbox value in database in asp.net mvc? : Asp.Net MVC
1.how to encrpt query string in asp.net? 2.there are 10000 records then i wnat display 5000 records one gridview and 5000 records another grid view what is the process?
when a request is made in Life cycle of ASP.NET page .
Why session is necessary in web application?
What is a multilingual website?