日期:2014-05-16 浏览次数:20434 次
SqlDataReader dr;
SqlConnection con = new SqlConnection(@"Data Source=477E67263580491\SQLEXPRESS;Initial Catalog=test_db;Integrated Security=True");
SqlCommand com = new SqlCommand("select course.* ,faculty.name,faculty.num from course,faculty where course.faculty_id"+" ="+tb1.Text+"and"+" faculty.faculty_id"+"="+tb1.Text, con);
con.Open();
dr=com.ExecuteReader();
if (dr.HasRows == true)
{
DataRow drow = dt.NewRow();
while (dr.Read())
{
for (int ind = 0; ind < dr.FieldCount ; ind++)
drow[ind]= dr.GetString(ind);
}
dt.Rows.Add(drow);
}
dr.Close();
gv.DataSource = dt; ///这里的gv是一个datagridview的name dt是指datatable对象。
con.Close();