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 the server control tags in asp.net.?
IN an ASP.NET Web application if there is any error, how can you debug?
In which event of the page viewstate is available?
What are the elements of a website?
Explain the main differences between asp and asp.net?
if i want to give an alert message like "try after sometime" to a web page which is being seen by other person.if a web page is not seen by anyone then it should display otherwise it show a display a message stating that other person is viewing so try after some time........how can i implement this.
Where you store Connection string in "Web.Config" file in ASP.NET?
Write some code using interfaces, virtual methods, and an abstract class`
Where do the cookie state and session state information be stored?
Explain about the Class view window?
What are the ways to show data grid inside a data grid for a master details type of tables? If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?
i want the asp.net technical questions and answeres
What is csrf attack in asp.net?
What is the difference between an htmlinputcheckbox control and an htmlinputradiobutton control?
Describe the Server Control Events of ASP.NET?