通过学号来查找sc表中的信息,成功了,
然后我套用格式,想通过姓名来查找,代码如下,结果出错了,因为第一次借触C#,也不知道错在哪,求指导
String sql2 = String.Format("select * from sc where sname= '{0}'", name);
connection.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql2, connection);
SqlCommand command = new SqlCommand(sql2, connection);
int num = Convert.ToInt32(command.ExecuteScalar());
if (num > 0)
{
DataSet ds = new DataSet();
sda.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
else { MessageBox.Show("姓名有误!请重新输入!"); }
然后我套用格式,想通过姓名来查找,代码如下,结果出错了,因为第一次借触C#,也不知道错在哪,求指导
String sql2 = String.Format("select * from sc where sname= '{0}'", name);
connection.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql2, connection);
SqlCommand command = new SqlCommand(sql2, connection);
int num = Convert.ToInt32(command.ExecuteScalar());
if (num > 0)
{
DataSet ds = new DataSet();
sda.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
else { MessageBox.Show("姓名有误!请重新输入!"); }