Wednesday, February 6, 2008

Using Keyword advantage in framework 2.0

The below code getting the employee details, but connection and command object declared in through using Keyword.one of the advantage of using keyword you no need to close the connection


using (SqlConnection myconn = new SqlConnection(connstring))
{
using (SqlCommand mycomm = new SqlCommand("select * from employee", myconn))
{
mycomm.CommandType = CommandType.StoredProcedure;
myconn.Open(); /////Here u opened the connection but no close
SqlDataReader myread;
myread = mycomm.ExecuteReader();
dt.Load(myread);
}
}
Note
This above code work only in C#