我正在嘗試在ms訪問數據庫中插入我的客戶端的用戶標識時出現錯誤。OLEDB中的溢出異常
我得到的錯誤是溢出。
當我試圖插入其獲取上述錯誤。
我正在使用這些代碼。
OleDbCommand cmd = new OleDbCommand("insert into UserInfo " + "([firstname], [lastname], [gender], [occupation], [expirydate], [UserId], [phoneno]) " + " values('" + txt_FirstName.Text + "','" + txt_LastName.Text + "','" + cmb_Gender.Text + "','" + cmb_Occupation.Text + "','" + txt_expiryDate.Text + "','" + txt_HardDiskId.Text + "','" + txt_PhoneNo.Text + "');", con);
OleDbCommand cmd1 = new OleDbCommand("select * from UserInfo where (HardDiskId='" + txt_HardDiskId.Text + "')", con);
int temp = 0;
try
{
con.Open();
string count = (string)cmd1.ExecuteScalar();
if ((count == "") || (count == null))
{
temp = cmd.ExecuteNonQuery();
if (temp > 0)
{
MessageBox.Show("User ID of " + txt_FirstName.Text + " " + txt_LastName.Text + " has been added");
}
else
{
MessageBox.Show("Record not added");
}
}
else
{
MessageBox.Show("User ID of " + txt_FirstName.Text + " already exists. Try another user ID.");
}
}
您是否收到此錯誤?您是否可以發佈_exact_錯誤/異常消息? – Oded
temp = cmd.ExecuteNonQuery();在這一行 –
順便提一下,連接SQL的字符串不是一個好主意。您的代碼對[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)開放。 – Oded