当在窗体应用程序的文本字段中输入特定学生ID时,我需要显示学生的信息

时间:2012-08-22 09:55:33

标签: c# ado.net

command.CommandText = "SELECT * FROM student details WHERE StudentID=@StudentID";

如何修改它以在上述程序语句中包含用户输入学生ID?

2 个答案:

答案 0 :(得分:1)

如果我理解正确,请使用:

command.Parameters.AddWithValue("@StudentID", int.Parse(yourTextBox.Text));

答案 1 :(得分:1)

我猜你想要这个(虽然你的问题有点模糊):

int studentId;
if (int.TryParse(textbox1.Text, out studentId)) {
    command.Parameters.AddWithValue("@StudentID", studentId);
}