【问题标题】:I keep getting the error System.Data.SQLite.SQLiteException: 'SQL logic error near "into": syntax error'我不断收到错误 System.Data.SQLite.SQLiteException:'“into”附近的 SQL 逻辑错误:语法错误'
【发布时间】:2019-10-16 09:11:58
【问题描述】:

我无法弄清楚代码有什么问题 enter image description here

System.Data.SQLite.SQLiteException: 'SQL 逻辑错误 “进入”附近:语法错误'

    private void BtnUpdate_Click(object sender, EventArgs e)
    {

        string StudentIDq = "update into Student (StudentID, ExamBoard, Firstname, Surname, Pure, Statistics, Mechanics, Total, " + "Average, Rank) values ('" + txtStudentID.Text + ", " + cmbExamBoard + ", " + txtFirstname.Text + "," + "" + txtSurname.Text + "," + txtPure.Text + ", " + txtStats.Text + "," + txtMechanics.Text + " + " + txtTS.Text + "," + txtAvrg.Text + "," + txtRank.Text + ")";


        ExecuteQuery(StudentIDq);
        LoadData();


    }

【问题讨论】:

  • 只需将update into 替换为insert into。
  • 还阅读了sql注入。

标签: c# sql database sqlite


【解决方案1】:
  private void BtnUpdate_Click(object sender, EventArgs e)
{

    string StudentIDq = "insert into Student (StudentID, ExamBoard, Firstname, Surname, Pure, Statistics, Mechanics, Total, " + "Average, Rank) values ('" + txtStudentID.Text + ", " + cmbExamBoard + ", " + txtFirstname.Text + "," + "" + txtSurname.Text + "," + txtPure.Text + ", " + txtStats.Text + "," + txtMechanics.Text + " + " + txtTS.Text + "," + txtAvrg.Text + "," + txtRank.Text + ")";


    ExecuteQuery(StudentIDq);
    LoadData();


}

【讨论】:

  • 它不起作用它仍然给我错误 System.Data.SQLite.SQLiteException: 'SQL 逻辑错误无法识别的令牌:'123, System.Windows.Forms.ComboBox, Items.Count: 4, qw,w2,56, 56,89 + 89,89,1)""
【解决方案2】:

如果您要更新列,查询将是这样的

    string StudentIDq = "update Student set StudentID=" + txtStudentID.Text + ", ExamBoard= " + cmbExamBoard + ", Firstname='" + txtFirstname.Text + "', Surname='" + txtSurname.Text + "', Pure='" + txtPure.Text + "', Statistics='" + txtStats.Text + "', Mechanics='" + txtMechanics.Text + "' , Total=" + txtTS.Text + ", " + "Average=" + txtAvrg.Text + ", Rank=" + txtRank.Text + ") ;

还要添加 Where 条件,否则所有列都会更新

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    相关资源
    最近更新 更多