Tuesday, 6 March 2012

Making Database Connection With Sql Server 2005 C#



string connectionstring = "server=MUKESH-PC\\SQLEXPRESS;database=Chat;trusted_connection=yes";
SqlConnection con = new SqlConnection(connectionstring);
SqlDataAdapter adp = new SqlDataAdapter("select * from users", con);
DataSet ds = new DataSet();
adp.Fill(ds, "student");
int s=ds.Tables[0].Rows.Count;

Get Values in the Dataset

First Row
String field1=ds.Tables[0].Rows[0].ItemArray[0].ToString();
String field2=ds.Tables[0].Rows[0].ItemArray[1].ToString();

Second Row
String field1=ds.Tables[0].Rows[1].ItemArray[0].ToString();
String field2=ds.Tables[0].Rows[1].ItemArray[1].ToString();

No comments:

Post a Comment

IE7 Issues Text Indent

                 Unfortunately IE 7 is still widespread among the users hence while theming we have to give special importance to the grea...