南宫云阳 2021-09-25 10:48 采纳率: 66.7%
浏览 44

这个是SQL的语句有错吗?怎么老是报语法错误?

按照教材上写的,教材上是2015版,我用的是2019版,调用SQL的语句不知道哪里出错了,一直显示语法错误。

此异常最初是在此调用堆栈中引发的: 
    System.Data.SqlClient.SqlConnection.OnError(System.Data.SqlClient.SqlException, bool, System.Action<System.Action>)
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(System.Data.SqlClient.TdsParserStateObject, bool, bool)
    System.Data.SqlClient.TdsParser.TryRun(System.Data.SqlClient.RunBehavior, System.Data.SqlClient.SqlCommand, System.Data.SqlClient.SqlDataReader, System.Data.SqlClient.BulkCopySimpleResultSet, System.Data.SqlClient.TdsParserStateObject, out bool)
    System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(string, bool, int, bool)
    System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(System.Threading.Tasks.TaskCompletionSource<object>, string, bool, int, out bool, bool, bool)
    System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    MyDD.DataOperator.ExecSQLResult(string) - 位于 DataOperator.cs
    MyDD.Frm_Login.pboxLogin_Click(object, System.EventArgs) - 位于 Frm_Login.cs
    System.Windows.Forms.Control.OnClick(System.EventArgs)
    System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message, System.Windows.Forms.MouseButtons, int)
    ...
    [调用堆栈已截断]

```c#
 if(ValidateInput())
            {
                string sql = "select count(*) from tb_User where ID= " + int.Parse(txtID.Text.Trim())
                    + "and Pwd = '" + txtPwd.Text.Trim() + "'";
                int num = dataoper.ExecSQL(sql);
                if(num==1)
                {
                    PublicClass.loginID = int.Parse(txtID.Text.Trim());
                    if(cboxRemember.Checked)
                    {
                        dataoper.ExecSQLResult("updata tb_User set Remember=1 where ID= " + int.Parse(txtID.Text.Trim()));
                        if (cboxAutoLogin.Checked)
                            dataoper.ExecSQLResult("updata tb_User set AutoLogin=1 where ID= " + int.Parse(txtID.Text.Trim()));
                    }
                    else
                    {
                        dataoper.ExecSQLResult("updata tb_User set Remember=0 where ID= " + int.Parse(txtID.Text.Trim()));
                        dataoper.ExecSQLResult("updata tb_User set AutoLogin=0 where ID= " + int.Parse(txtID.Text.Trim()));
                    }
                    dataoper.ExecSQLResult("updata tb_User set Flag=1 where ID= " + int.Parse(txtID.Text.Trim()));
                    Frm_Main frmMain = new Frm_Main();
                    frmMain.Show();
                    this.Visible = false;


        private static string connString = @"Data Source=0BOJB1X0ET7EZM4;Database=db_MyQQ;User ID=sa;Pwd=123456;";
        public static SqlConnection connection = new SqlConnection(connString);
        public int ExecSQL(string sql)
        {
            SqlCommand command = new SqlCommand(sql, connection);
            if (connection.State == ConnectionState.Closed)
                connection.Open();
            int num = Convert.ToInt32(command.ExecuteScalar());
            connection.Close();
            return num;
        }
        public int ExecSQLResult(string sql)
        {
            SqlCommand command = new SqlCommand(sql, connection);
            if (connection.State == ConnectionState.Closed)
                connection.Open();
            int result = command.ExecuteNonQuery();
            connection.Close();
            return result;


img

img

img

img

img

  • 写回答

1条回答 默认 最新

  • gs0038 2021-09-25 10:57
    关注

    updata 换成 update

    评论

报告相同问题?

问题事件

  • 创建了问题 9月25日

悬赏问题

  • ¥20 c语言写的8051单片机存储器mt29的模块程序
  • ¥60 求直线方程 使平面上n个点在直线同侧并且距离总和最小
  • ¥50 java算法,给定试题的难度数量(简单,普通,困难),和试题类型数量(单选,多选,判断),以及题库中各种类型的题有多少道,求能否随机抽题。
  • ¥50 rk3588板端推理
  • ¥250 opencv怎么去掉 数字0中间的斜杠。
  • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
  • ¥250 paddleocr带斜线的0很容易识别成9
  • ¥15 电子档案元素采集(tiff及PDF扫描图片)
  • ¥15 flink-sql-connector-rabbitmq使用
  • ¥15 zynq7015,PCIE读写延时偏大