Sequence to connect and retrieve data from database useig
dataset ?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
What is ado.net in vb net?
What is the main difference between ADO and ADO.Net
Using Ado.net, what front ends and back ends can you use?
What is bubbled event?
how can implement dropdownlist in particular of dataset when try to update?
how would i implement dropdownlist in gridview using c#
How to check if a datareader is closed or opened?
How to pass values into a datatable?
What are the Different layers in ADO.Net?
How to call the SQL commands asynchronously in ADO.NET version 2.0
What is the difference in an abstract class and an interface?
What is method to get XML and schema from Dataset?