日期:2014-05-18 浏览次数:20962 次
SqlConnection conn = new SqlConnection("数据库连接字符串"); string sql = " select * from 表 where 字段='" + textbox1.text + "'";//根据textbox中的text动态生成sql语句 SqlDataAdapter dr = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); dr.Fill(dt); this.datagridview1.datasource = dt;
------解决方案--------------------
SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=MH\SQLEXPRESS;Initial Catalog=hs;User Id=sa;Password=;"; con.Open(); SqlDataAdapter adapter = new SqlDataAdapter("select * from BillList where code='"+textBox1.Text+"'",con); DataSet ds = new DataSet(); adapter.Fill(ds, "BillList"); dataGridView1.DataSource = ds.Tables["BillList"];
------解决方案--------------------
SqlConnection conn = new SqlConnection("数据库连接字符串");
string sql = textbox1.text //根据textbox中的text动态生成sql语句
SqlDataAdapter dr = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
dr.Fill(dt);
this.datagridview1.datasource = dt;
或者是这样
------解决方案--------------------
http://blog.csdn.net/xianfajushi/article/details/7643705