2013-02-04 401 views
0
   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 [email protected])"; 
        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 [email protected]')"; 
         cmd.Parameters.AddWithValue("@1", emp_id); 
         cmd.ExecuteNonQuery(); 
         res.Write("deleted"); 
        } 
        else 
        { 
         res.Write("zero"); 
        } 
        con.Close(); 

       } 

我收到SQL錯誤附近dr = cmd.ExecuteReader();MySql.Data.MySqlClient.MySqlException(0X80004005)

錯誤消息:

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 

回答

3

了MySqlClient預計?參數字符,而不是@

另外我不確定1是否爲有效參數na我。嘗試使用?p_1

最後,作爲RhysW提到過,在你的SELECT語句在DELETE語句額外'))

+0

+1以及看準 – RhysW

+0

而@ 1之後有第二個查詢的額外「這可能是搞砸了 – RhysW

+0

10個人爲你的幫助..mehmet你wer rit ..datw是非常愚蠢的錯誤,我做.. – Aadam

相關問題