我正在尝试创建一个注册表单。我想进行验证检查,如果文本框中的 ID 已经存在,它将显示错误消息。但是,每当我尝试搜索 ID 并将其放入字符串中时,都会出现错误
An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
这是我的代码:
public SignUpForm()
{
InitializeComponent();
}
// Connection String
SqlCeConnection connect = new SqlCeConnection("Data Source= Accounts.sdf;Persist Security Info=false;");
private void btnRegister_Click(object sender, EventArgs e) {
String verifyID = "";
connect.Open();
using (SqlCeCommand cmd = new SqlCeCommand("SELECT Student ID FROM Users WHERE Student ID = @ID", connect))
{
cmd.Parameters.AddWithValue("@ID", txtID.Text);
using (SqlCeDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
verifyID = (string)reader["Student ID"];
}
}
}
txtTEMP.Text = verifyID;