Database to Data Grid view:
string connectionString = null; //connection string
string sql = null; //query from db
connectionString = "Data Source=LAB6-168;Initial Catalog=schoolm;User ID=sa;Password=aptech";
SqlConnection cnn = new SqlConnection(connectionString); //con object
cnn.Open(); //coneection open form db
sql = "SELECT * FROM student"; //query
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn); //reads all records from db
DataSet ds = new DataSet();
dscmd.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
No comments:
Post a Comment