【问题标题】:MySql.Data.MySqlClient.MySqlException (0x80004005) [closed]MySql.Data.MySqlClient.MySqlException (0x80004005) [关闭]
【发布时间】:2013-02-04 12:56:07
【问题描述】:
               try
                {

                   // Console.WriteLine("wtf");
                    con.ConnectionString = WebConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
                    cmd.Connection = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    con.Open();
                    cmd.CommandText = "select count(*) from hr WHERE emp_id=@1)";
                    cmd.Parameters.AddWithValue("@1", emp_id);

                   dr = cmd.ExecuteReader();
                   int count = 0;
                    while (dr.Read())
                     {
                         count = dr.GetInt32(0);
                     }
                     dr.Close();
                     cmd.Dispose();
                     cmd.Parameters.Clear();
                    if (count > 0)
                    {

                        cmd.CommandText = "DELETE FROM hr WHERE emp_id=@1')";
                        cmd.Parameters.AddWithValue("@1", emp_id);
                        cmd.ExecuteNonQuery();
                        res.Write("deleted");
                    }
                    else
                    {
                        res.Write("zero");
                    }
                    con.Close();

                }

dr = cmd.ExecuteReader(); 附近出现 sql 错误

错误信息:

 MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL
 syntax; check the manual that corresponds to your MySQL server version for the right
 syntax to use near ')' at line 1 at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at 
MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at 
MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& 
insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
 at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at 
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at 
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at 
prod.Controller.HR.HRDel.ProcessRequest(HttpContext context

【问题讨论】:

    标签: c# mysql


    【解决方案1】:

    MySqlClient 需要 ? 参数 char 而不是 @

    我也不确定1 是否是一个有效的参数名称。尝试使用?p_1

    最后,正如 RhysW 所说,在你的 DELETE 语句中有一个额外的 ') 在你的 SELECT 语句中有一个 )

    【讨论】:

    • 在@1 之后的第二个查询中还有一个额外的 ' 可能会搞砸
    • 10x 伙计们为您提供帮助..mehmet u wer rit..datw 是我犯的非常愚蠢的错误..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 2013-06-16
    相关资源
    最近更新 更多