日期:2014-05-20 浏览次数:20728 次
SqlConnection cn = new SqlConnection("server=localhost;database=Labiary;integrated security=true"); DataSet ds = new DataSet(); String name = textBox1.Text.Trim(); SqlCommand cmd = new SqlCommand("select 书名 from Books where 书名 like" + name + "", cn); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { Console.WriteLine(ds.Tables[0].Rows[i][j].ToString()); DataTable dt = ds.Tables[0]; this.dataGridView1.DataSource = dt; } }