Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is a control toolbox?

961


How does entity framework work?

914


What is acid in ado.net?

1023


What is difference between executenonquery and executequery?

962


What is maximum pool size in ado.net connection string?

970


What is the default timeout specified for "sqlcommand.commandtimeout" property?

1041


What are the parameters that control most of connection pooling behaviours?

1069


Is it possible to load multiple tables in a Dataset?

1068


What is data relation?

896


What are the drawbacks of using ado.net?

967


What are the benefits of using ado.net?

1002


Which method in OLEDBAdapter is used to populate dataset with records?

1019


What are the disadvantages of using datalist?

1027


What are the namespaces used in ADO.Net to connect to a database?

1203


How can we perform transactions in .net?

1056