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...


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 function and trigger?

1 Answers   HCL,


Which ado.net object is very fast in getting data from the database?

0 Answers  


Explain what are acid properties?

0 Answers  


What is full form of ado?

0 Answers  


Name which operations can you not perform on an ado.net dataset?

0 Answers  


What is the full form of ado?

0 Answers  


Where do you store connection string ?

3 Answers   Digital GlobalSoft,


What DataReader class do in ADO.NET ?

0 Answers   NA,


Which method in OLEDBAdapter is used to populate dataset with records?

0 Answers  


What is the main difference between ADO and ADO.Net

4 Answers   HCL,


What are the advantages and drawbacks of using ado.net?

0 Answers  


How to store data in memory?

0 Answers  


Categories