这个c#里写的sql到底怎么了!
各位,不好意思,我刚学,下面是我想用datagripview这个控件,可是不知道为什么不显示数据,网上的内容又多又杂,越看越迷茫。。。。高手们,谁能教下我,难道是那个sql语句写错了??
--------------------------------------------------------------------------------------------------
private void btnSearch_Click_1(object sender, EventArgs e)
{
DataTable dt1 = new DataTable();
int i = 0; //intn=0;
string s1 = "", s2 = "";
string strsql;
s1 = textBox1.Text;
s2 = textBox3.Text;
i = Convert.ToInt32(textBox2.Text);
SqlConnection objSqlConnection = new SqlConnection("workstation id=Song;Integrated Security=SSPI;database=yohamilky");
objSqlConnection.Open();
MessageBox.Show("数据库连接成功", "好");
try
{
strsql = "select Order_ID,Milk_ID,Amount,Beginning_Day,Days from "
+ "Customer , Order where Customer.Customer_ID=Order.Customer_ID and Customer_name ="
+ s1 +" and building_NO ="
+ i + " and Door_NO = " + s2;
MessageBox.Show(strsql);
da1 = new SqlDataAdapter(strsql, objSqlConnection);
dt1.Clear();
dataGridView1.DataSource = dt1.DefaultView;
MessageBox.Show("添加成功!");
//SqlConnection con = new SqlConnection("context connection=true");
}
catch (Exception)
{
MessageBox.Show("意外!");
}
}
------------------------------------------------------------------------------
谢谢!