【问题标题】:INSERT INTO sql sentence is not working"System.Data.OleDb.OleDbException"INSERT INTO sql 语句不起作用“System.Data.OleDb.OleDbException”
【发布时间】:2017-03-09 16:42:11
【问题描述】:

我正在制作一个注册页面 我的代码有什么问题? 当我在浏览器中查看程序时,它说: (INSERT INTO 语句中的语法错误。

说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Data.OleDb.OleDbException:INSERT INTO 语句中的语法错误。)

public partial class Sign_Up2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtPass.Text != "" &&
            txtUname.Text != "" &&
            txtRePass.Text != "")
        {
            if (txtPass.Text.ToString().Trim() == txtRePass.Text.ToString().Trim())
            {
                string str ="INSERT INTO T1 (Username,Password) VALUES('" + txtUname.Text.ToString() + "','" + txtPass.Text.ToString() + "');";
                DAL.ChangeTable(str);
                Response.Redirect("log in.aspx");
            }
        }
    }
}

【问题讨论】:

  • 当用户名或密码包含' 字符时会发生什么? (提示:你有一个安全漏洞。)
  • 是的 - 撇号(或分号)嵌入到变量中时可能会让您感到悲伤。您应该使用参数。

标签: c# sql asp.net


【解决方案1】:

从查询中删除分号

"INSERT INTO T1 (Username,Password) VALUES('" + txtUname.Text.ToString() + "','" + txtPass.Text.ToString() + "');";

"INSERT INTO T1 (Username,Password) VALUES('" + txtUname.Text.ToString() + "','" + txtPass.Text.ToString() + "')";

【讨论】:

  • 检查右大括号后的最后一个分号
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多