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 the difference between the clone() and copy() methods of the dataset class?

1024


What is sqldatasource?

885


What are the key events of sqlconnection class?

1126


How do we use stored procedure in ADO.NET and how do we provide parameters to the stored procedures?

928


What is the use of ADO.NET and XML web services?

990


What is basic use of data view?

947


What are all the commands used with Data Adapter?

979


Which architecture does Datasets follow?

993


How to connect and retrieve data from database using dataset

989


What are disadvantages of microsoft-provided data provider classes in ado.net?

969


What is ado rdo dao in visual basic?

1106


What are the benefits of using ado.net?

957


How can we serialize the dataset object?

961


How to create dynamic gridview?

988


What is data reader in ado.net?

961