Is it possible to use local variables in MySqlClient? RRS feed

  • Question

  • I am trying to do something like the following from within C#:

    MySqlCommand cmd = connection.CreateCommand();
    cmd.CommandText = "
    SELECT @StatusId := StatusId FROM MyTable WHERE Id = @CurrentId;
    SELECT @StatusId;
    cmd.Parameters.Add("CurrentId", MySqlDbType.Int16).Value = 10;
    int statusId = (int)cmd.ExecuteScalar();

    But when I execut the command, an error is thrown saying: Parameter @StatusId must be defined.

    In Sql Server, you do something like DECLARE @StatusId int before that line, but it seems that only works for stored procedures (in MySql).

    Anyone have any idea on how to get this to work?

    Friday, May 29, 2009 7:13 AM

All replies

  • I think in this instance @StatusId would need to be added to the Parameters collection as an output parameter since it isn't really part of a result set.

    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, June 1, 2009 3:46 PM