开发者

Parameterized MySql INSERT query not having right parameters value

I'm trying to do a basic ins开发者_StackOverflow中文版ert statement using a parameterized query. My problem is whatever the syntax I'm using it seems like the query is being done with all parameters set to null instead of their appropriate values (unless I hard-code the value in the command text).

Here is the code :

m_Command.CommandText = "INSERT INTO " + s_TracesTabelName + " (DateTimeTraceCreated,
Span, CenterFrequency, Data, DateTimeTestStarted) VALUES (@traceTime, @Span, 
@CenterFrequency, @Data, @testTime)";


//just trying another syntax
MySqlParameter param = m_Command.CreateParameter();
param.MySqlDbType = MySqlDbType.Datetime;
param.ParameterName = "@traceTime";
param.Value = trace.TimeCreated;
m_Command.Parameters.Add(param);

//m_Command.Parameters.Add("@traceTime",MySqlDbType.Datetime,8,"DateTimeTraceCreated");
//m_Command.Parameters["@traceTime"].Value = trace.TimeCreated;
m_Command.Parameters.Add("@Span", trace.Span);
m_Command.Parameters.Add("@CenterFrequency", trace.CenterFrequency);
m_Command.Parameters.Add("@Data", data);
m_Command.Parameters.Add("@testTime", testStarted);

        try 
        {
            m_Connection.Open();
            m_Command.ExecuteNonQuery();
        }
        catch(Exception e)
        {
            Console.WriteLine("Error Connecting to Database\n");
            //errorlog
        }
        finally
        {
            m_Connection.Close();
        }

The three different syntaxes lead me to null parameters' value.

ps : I've seen many people using command.Parameters.AddWithValue() method, but I seem to just don't have it.

Kind regards, Ben


Could be your version of mysql ADO provider? C# MySqlParameter problem

Try with ? instead of @

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜