What is sequence of code in retrieving data from database ?
Answer Posted / senthil kumar
if you use sql server
SqlConnection con = new SqlConnection();
con.ConnectionString ="Data Source=servername;Initial
Catalog=databasename;";
con.Open();
String sql;
sql ="select * from tbl_tablename";
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataReader reader;
reader = cmd.ExecuteReader();
while(reader.Read)
{
Console.WriteLine("Field1:"+read.GetString(0));
Console.WriteLine("Field1:"+read.GetString(1));
Console.WriteLine("Field1:"+read.GetValue(2));
}
con.Close();
}
| Is This Answer Correct ? | 9 Yes | 4 No |
Post New Answer View All Answers
What is a control toolbox?
How does entity framework work?
What is acid in ado.net?
What is difference between executenonquery and executequery?
What is maximum pool size in ado.net connection string?
What is the default timeout specified for "sqlcommand.commandtimeout" property?
What are the parameters that control most of connection pooling behaviours?
Is it possible to load multiple tables in a Dataset?
What is data relation?
What are the drawbacks of using ado.net?
What are the benefits of using ado.net?
Which method in OLEDBAdapter is used to populate dataset with records?
What are the disadvantages of using datalist?
What are the namespaces used in ADO.Net to connect to a database?
How can we perform transactions in .net?