我想創建一個註冊表單。我想進行驗證檢查,如果文本框中的ID已經存在,它會顯示錯誤消息。然而,每當我嘗試搜索ID,並把它轉換成字符串我得到一個錯誤C#SQL搜索結果到一個字符串/文本框
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;
即使列名在他們的空間?我仍然得到錯誤 – user2782104
請看Saagar的回答:) – Minh