private void 查询信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
string No = Convert.ToString(textBox1.Text).Trim();
string a = "select 姓名,性别,生日,籍贯,专业 from student where 学号='" + No + "'";
if (textBox1.Text == "")
{
MessageBox.Show("请输入学号");
textBox1.Focus();
}
else
{
try
{
SqlCommand cmd = new SqlCommand(a, connstr);
connstr.Open();
DataSet ds = new DataSet();
SqlDataAdapter SDA = new SqlDataAdapter(a, connstr);
SDA.Fill(ds, "student");
dataGridView1.DataSource = ds.Tables["student"];
connstr.Close();
}catch(Exception ex)
{MessageBox.Show("Error:"+ex.Message);}
}
}
老问题刚解决新问题又来了:
上面的代码实现输入学号查询学生相关信息
但如果你输入的是别人的学号也可以查别人的信息
这要如何限制呢
这是在用用户名,密码登录后出现的用户查询界面。但登录者也可查别人的信息,或者有什么方法能直接查询登录者自己的信息吗?
做限定。怎么做?
|