C# : how to get a value from a dataset?

R

RD

clsConnect ObjConnect = new clsConnect();

string ConnectionString=ObjConnect.Connstring;

SqlConnection myConn=new SqlConnection(ConnectionString);

SqlCommand myCMD = new SqlCommand("SELECT * from Customer Where CustomerId
= 1",myConn);


SqlDataAdapter myDA = new SqlDataAdapter();

myDA.SelectCommand = myCMD;

myConn.Open();

DataSet myDS = new DataSet();

myDA.Fill(myDS);

----------------------------------------------------------------------------
-

Now I want to get the values of specific fields.
(Lastname,firstname,------------) How can I do that?

Thanks

RD
 
A

Alvin Bruney

for(int i = 0; i < ds.Tables[0].Rows.Count; i++)

{

ds.Tables[0].Rows[0].ToString();// = first name
ds.Tables[0].Rows[1].ToString();// = last name
ds.Tables[0].Rows[2].ToString();// = ---------
}
for simple values you really should consider using a data reader instead of
a dataset. its faster because there is less overhead
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top