110,536
社区成员
发帖
与我相关
我的任务
分享
string ConStr = @"server=.\SQLEXPRESS;uid=sa;pwd=sa;database=Northwind";
SqlConnection con = new SqlConnection(ConStr);
string SqlStr = "select CustomerID,RequiredDate,Freight,ShipName,ShipName from Orders where Freight between @dtp1 and @dtp2";
//下面怎么给@dtp1和dtp2赋值啊,@dtp1对应的值为dateTimePicker1.Text @dtp2对应的值为dateTimePicker1.Text
SqlCommand cmd = new SqlCommand(SqlStr, con);
cmd.Parameters.AddWithValue("@dtp1", textBox1.Text);
cmd.Parameters.AddWithValue("@dtp2", textBox2.Text);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
string ConStr = @"server=.\SQLEXPRESS;uid=sa;pwd=sa;database=Northwind";
SqlConnection con = new SqlConnection(ConStr);
string SqlStr = "select CustomerID,RequiredDate,Freight,ShipName,ShipName from Orders where len(Freight) between @dtp1 and @dtp2";
//下面怎么给@dtp1和dtp2赋值啊,@dtp1对应的值为dateTimePicker1.Text @dtp2对应的值为dateTimePicker1.Text
SqlCommand cmd = new SqlCommand(SqlStr, con);
cmd.Parameters.AddWithValue("@dtp1", textBox1.Text);
cmd.Parameters.AddWithValue("@dtp2", textBox2.Text);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];