Sequence to connect and retrieve data from database useig
dataset ?

Answer Posted / pushpendra singh

step 1---// Connection creation using Connection string
to connect SQL database

SqlConnection conn=new SqlConnection("data
source=server_name;initial catalog=database_name;integrated
security=sspi");

conn.Open();

step2----execute command using SqlCommand Class.

SqlCommand cmd=new SqlCommand("select * from asd",conn);

DataSet ds=new DataSet();

SqlDataAdapter da=new DataAdapter();
da.SelectCommand=cmd;

//insert data from dataadapter to dataset

da.Fill(ds);

dataGridView1.DataSource=ds.Tables[0];
conn.Close();

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different ado.net namespaces are available in .net?

752


Explain how can we load multiple tables in to dataset?

700


Explain the difference between sqlcommand object and command behavior object?

753


What is a string variable?

660


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

806


Why edit is not possible in repeater?

699


How do you implement locking concept for dataset?

750


Can datareader hold data from multiple tables?

867


What is ado in agriculture?

692


How to aggregating data across related tables?

775


How to bind the controls(best practice) comboboxes to the data in the dataset?

794


What are the methods of XML dataset object?

797


Give an example that shows how to execute a stored procedure in ado.net?

794


What is the current version of entity framework?

676


Which name space is used to get assembly details?

710