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

Difference between ADO and ADO.Net

4 Answers   IBM,


What is ado and rdo?

0 Answers  


What are the core objects of ADO.NET?

0 Answers  


What provider ADO.net use by default?

10 Answers   Accenture, TCS,


Which one of the following objects is a high-level abstraction of the connection and command objects in ado.net?

0 Answers  


i have two textboxes one for user name and another for password . i have a table name compare(which contains name,passwod etc.,)my doubt is how compare username textbox with name column and how compare password textbox with passwod column. i want the code

9 Answers   Wipro,


How does ado.net work?

0 Answers  


What is commandbuilder in ado.net?

0 Answers  


What are dcl commands?

0 Answers  


What is fill method in ado.net?

0 Answers  


What are the two fundamental objects in ADO.NET?

8 Answers   Ksb, TCS,


The answers which posted above is not satisfied my requirement? Can some one post teh exact answer? Thanx

0 Answers  


Categories