异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
string s1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Library.mdb;Persist Security Info=True";string s2 = "select ReaderNo from [Readerinfo] where ReaderNo='" + TextID.Text + "'";
OleDbConnection conn = new OleDbConnection(s1);
conn.Open();
OleDbCommand cmd = new OleDbCommand(s2, conn);
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
string strreaderno = dr["ReaderNo"].ToString().Trim();
if (this.TextID.Text == strreaderno)
{
MessageBox.Show("该用户编号已经存在!");
this.TextID.Text = "";
this.TextauPs.Text = "";
this.TextID.Focus();
}
}
}
else if (this.TextauPs.Text =="") return;
else
{
conn.Close();
conn.Open();
cmd.CommandText = "insert into [Readerinfo](ReaderNo,ReaderName,Sex,Password,Address,ReaderPhone,ReaderEmal,IssueTag,IssueTagUsed,ReaderType,iDate) values('" + TextID.Text + "','" + TextName.Text + "','" + comboBox1.Text + "','" + TextauPs.Text + "','" + TextauAddress.Text + "','" + textBoxPh.Text + "','" + TextEmail.Text + "','" + textBoxMaxbook.Text + "','" + textBoxBorbook.Text + "','" + comboBoxleib.Text + "','" + TextaddDate.Text + "')";
cmd.Connection = conn;
cmd.ExecuteNonQuery();
MessageBox.Show("注册成功!");
this.Close();
}
conn.Close();
}
--------------------编程问答-------------------- 谢谢来看本帖的好心朋友 我已经解决这个问题咯 o(∩_∩)o... --------------------编程问答--------------------
sql语句错误。设置断点检查语句执行情况。
也有可能文本录入有注入字符 最常见就是 单撇号 '
补充:.NET技术 , ASP.NET