Sequence to connect and retrieve data from database useig
dataset ?

Answers were Sorted based on User's Feedback



Sequence to connect and retrieve data from database useig dataset ?..

Answer / a.anwar sadat

public SqlConnection con = new SqlConnection("server=anwar;
uid=sa; pwd=s;database=Employee;");
public SqlCommand cmd;
public SqlDataAdapter da;
public DataSet ds;

cmd = new SqlCommand("select * from empdetails", con);

da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "empdetails");
foreach(DataRow dr in ds.Tables["empdetails"].Rows)
{
txtempname.Text = dr["name"].ToString();
txtdob.Text = dr["dob"].ToString();
txtstreetname.Text = dr["street"].ToString();
} // foreach

Is This Answer Correct ?    13 Yes 6 No

Sequence to connect and retrieve data from database useig dataset ?..

Answer / vaidyanathan r.

The sequence is
Step 1: Create a Connection Object with Connection String
Eg: <Provider**>Connection ActiveConnection = new
<Provider**>Connection(<ConnectionString>)

Step 2: Create a Command Object with Command Text and the
created Connection Object

Eg: <Provider**>Command Qry = new <Provider**>Command
(<Command Text>, ActiveConnection)

Step 3: Set the command Type for the created Command
Eg: Qry.CommandType = CommandType.Text

Step 4: Create Data Adapter with the created Command
Eg: <Provider**>DataAdapter da = new
<Provider**>DataAdapter(Qry*);

Step 5: Create a DataSet Object.
Eg: DataSet ds = new DataSet();

Step 6: populate the dataset by calling the fill method of
Data adaper against the Data set object
Eg: da.Fill(ds);

__________________________________________________________
*Qry contains a select query (or) Stored Procedure Name
containing a Select Query

** If the provider is SQL server then the Connection type
is SQLConnection, Command type is SQLCommand and Data
adapter type is SQLDataAdapter.

Is This Answer Correct ?    3 Yes 3 No

Sequence to connect and retrieve data from database useig dataset ?..

Answer / ramakrushna

SqlConnection con = new SqlConnection();
con.ConnectionString = "server=munapc;
database=project1; User ID=sa; Password=niit";
con.Open();

string query = "select * from emp";
SqlDataAdapter da = new SqlDataAdapter(query, con);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;

con.Close();

Is This Answer Correct ?    2 Yes 2 No

Sequence to connect and retrieve data from database useig dataset ?..

Answer / 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

Sequence to connect and retrieve data from database useig dataset ?..

Answer / reply2anwar

public SqlConnection con = new SqlConnection("server=anwar;uid=sa; pwd=s;database=Employee;");
public SqlCommand cmd;
public SqlDataAdapter da;

private void RetriveData()
{
cmd = new SqlCommand("select * from empdetails", con)
DataSet ds = new DataSet();
using(da = new SqlDataAdapter(cmd))
{

da.Fill(ds, "empdetails");
foreach(DataRow dr in ds.Tables["empdetails"].Rows)
{
txtempname.Text = dr["name"].ToString();
txtdob.Text = dr["dob"].ToString();
txtstreetname.Text = dr["street"].ToString();
} // foreach
}
}

Is This Answer Correct ?    1 Yes 2 No

Sequence to connect and retrieve data from database useig dataset ?..

Answer / ashokdahiya

We r talking about vb.net not c# codding
system.data
system.data.sqlclient

dim con,s as string
con="Server=servername;database=name;uid=sa;pwd=;"
s="Select * from tablename"
dim ad as new sqldataadapter(s,con)
dim ds as dataset
ad.fill(ds)
dim dv as dataview= new dataview(ds.tables("tablename"))
dv.sort="Name desc"
listbox.datasource=ds
listbox.displayMember="Name"&"Age"&"sex"...

it will work fine thanx!

Is This Answer Correct ?    2 Yes 7 No

Post New Answer

More ADO.NET Interview Questions

What is ado.net in vb net?

0 Answers  


What is the main difference between ADO and ADO.Net

4 Answers   HCL,


Using Ado.net, what front ends and back ends can you use?

10 Answers  


What is bubbled event?

0 Answers  


how can implement dropdownlist in particular of dataset when try to update?

0 Answers   TCS,






how would i implement dropdownlist in gridview using c#

2 Answers  


How to check if a datareader is closed or opened?

1 Answers  


How to pass values into a datatable?

0 Answers  


What are the Different layers in ADO.Net?

7 Answers  


How to call the SQL commands asynchronously in ADO.NET version 2.0

4 Answers   DELL,


What is the difference in an abstract class and an interface?

0 Answers  


What is method to get XML and schema from Dataset?

2 Answers  


Categories