private void button1_Click(object sender, EventArgs e)
{ string text_ID=null;
string text_name=null;
string text_sdept=null;
string text_sex=null;
int index=0;
if (textBox1.Text != null)
{
++index;
}
if (textBox2 != null)
{ ++index;
}
if (textBox3.Text != null)
{ ++index;
}
if (radioButton1.Checked = true)
{ ++index;
}
else
{ ++index;
}
if (index < 4)
{
MessageBox.Show("请填写完整");
}
else
{ string sq = " Data Sourse=localhost; Initial Catalog=zyf_student; User ID=sa; pwd =zyf";
SqlConnection conn = new SqlConnection(sq);
try {
conn.Open();
SqlCommand com = new SqlCommand(); com.CommandText = "select sno ,sname,sdept,sex from student where sno ='" + text_ID + "'";
dataGridView1.DataSource = com.ExecuteNonQuery(); //本意是点击button实现查询,显示数据放在DATAGRIDVIEW
}
catch (SqlException ex)
{
MessageBox.Show("数据异常");
}
conn.Close();
}
}//现在的问题是我什么都没填写 datagridview 已经有结果了
程序开始运行就有了结果,与本意不符
很简单,null和空字符串是不一样的,
button1
textBox1
textBox2
textBox3
radiobox1
dataGridView1
我也是醉了...