#27 Named parameters problem

closed-works-for-me
nobody
None
5
2005-03-17
2005-02-20
Arild Fines
No

I had code like this:

SQLiteCommand cmd = new SQLiteCommand( "INSERT
INTO UserRoles " +
"(UserName, Role) VALUES(@UserName,
@Role)", conn );

SQLiteParameter userParm = cmd.Parameters.Add(
"@UserName", DbType.String );
SQLiteParameter roleParm = cmd.Parameters.Add(
"@Role", DbType.String );

userParm.Value = username;
roleParm.Value = role;
cmd.ExecuteNonQuery();

I got an exception with a message of "near \"?\": syntax
error".

Rewriting the code to use unnamed parameters work.

Discussion

  • Mattias Karlsson

    Logged In: YES
    user_id=1234220

    I use named parameters in a different way and it works just
    fine, code example below:
    using(SQLiteCommand Cmd = Conn.CreateCommand())
    {
    Cmd.Parameters.Add("@strGroup", strGroup);
    Cmd.Parameters.Add("@strLocation", strLocation);
    Cmd.Parameters.Add("@dtStartDate", dtStartDate);
    Cmd.Parameters.Add("@dtEndDate", dtEndDate);
    Cmd.Parameters.Add("@dtStartLunch", dtStartLunch);
    Cmd.Parameters.Add("@dtEndLunch", dtEndLunch);
    Cmd.CommandType = CommandType.Text;
    Cmd.CommandText = "INSERT INTO tblEvent"
    + " (strGroup, strLocation, dtStartDate, dtEndDate,
    dtStartLunch,dtEndLunch)"
    + " VALUES (@strGroup, @strLocation, @dtStartDate,
    @dtEndDate, @dtStartLunch, @dtEndLunch)";

    int nResult = Cmd.ExecuteNonQuery();
    }

     
  • Robert Foster

    Robert Foster - 2005-03-16

    Logged In: YES
    user_id=526041

    Could you provide samples of the data you are trying to insert?
    And perhaps a stack trace of the error, if possible.
    Thanks.

     
  • Arild Fines

    Arild Fines - 2005-03-16
    • status: open --> open-invalid
     
  • Arild Fines

    Arild Fines - 2005-03-16

    Logged In: YES
    user_id=676362

    Grrr, I tried to create a simple repro case, but was
    unsuccessfull. Could have been something specific about the
    data I was using at the time, but can't really remember what it
    was now.

     
  • Robert Foster

    Robert Foster - 2005-03-17
    • status: open-invalid --> closed-invalid
     
  • Robert Foster

    Robert Foster - 2005-03-17
    • status: closed-invalid --> closed-works-for-me
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks