Hello Friends
actually i m Fresher in the C# and ASP.Net so while doing coding i have some problems means how to use DATAREADER, DATAADAPTOR, DATATABLE and DATASETS.so, friends if any one is having basic ideas regaring this plz tell me. and the uses of all the above
thanks
Bhaskar
Bhaskar PimpalshendePosted Jan 9, 2008, 5:47 AM
Thanks a lot Manish.
and can u suggest me what is the Standard of Coding in the C# for example which rules we should apply while Declaring the Variable, strings etc and tell me Exception Handeling Specially.
if i want to populate the DropDown List what should i Use whether Datareader or Dataadaptor.
Manish If u have some Basic rules for the C# coding can u just mail me the Doc file
Thanks
Bhaskar
Blocked AccountPosted Jan 9, 2008, 2:23 AM
If u are the fresher then refer any book of ADO.NET. Here I am trying to give u the brief introduction of that.
For the Data Reader.
//Define Connection String
string connstring="Define your connection here";
string SQLquery="Write your query here";
// Establish Connection
SqlConnection Connection = new SqlConnection(connstring);
Connection.Open();
// Create command
SqlCommand command = new SqlCommand(Connection, SQLquery);
// Create a DataReader to ferry information back from the database
SqlDataReader reader;
reader = command.ExecuteReader();
//Iterate through the results
while (reader.Read()) {
//... Work with the current record ...
}
// Close the connection (will automatically close the reader)
Connection.Close();
For the Data Adapter//Define Connection String
string connstring="Define your connection here";
string SQLquery="Write your query here";
// Establish Connection
SqlConnection Connection = new SqlConnection(connstring);
Connection.Open();
// Create command
SqlCommand command = new SqlCommand(Connection, SQLquery);
// Create the DataAdapter
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
// Create the DataSet
DataSet dataSet = new DataSet();
// Fill the DataSet
dataAdapter.Fill(dataSet);
// Close the connection (will automatically close the reader)
Connection.Close();
// Now do the work with the dataset what ever you want.
Happy Coding!!