【发布时间】:2011-12-05 11:47:34
【问题描述】:
当我尝试在 ms access 数据库中插入客户端的用户 ID 时出现错误。
我得到的错误是溢出。
当我尝试插入时出现上述错误。
我正在使用这些代码。
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错误/异常消息吗?
-
temp = cmd.ExecuteNonQuery();在这一行
-
顺便说一句,为 SQL 连接字符串并不是一个好主意。您的代码对SQL Injection开放。
-
我得到的正是这个错误,只是溢出不超过那个
-
你能告诉我哪里出错了,因为我之前没有遇到过这样的错误
标签: c# winforms ms-access oledb