0

I'm trying to do a basic insert 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

1
  • Have you tried hard-coding the values instead of using parameters, if yes, is it working? Commented Mar 21, 2011 at 10:33

1 Answer 1

1

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

Try with ? instead of @

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.