last_insert_rowid

2004-06-11
2004-06-12
  • Nobody/Anonymous

    Can somebody explain me how can i get last_insert_rowid()?

    My tabUser:
    CREATE table tabUser (idUser INTEGER PRIMARY KEY,
    sFirstName char(31) not null default '', sLastName char(31) not null default '");

    I do:
    Cmd.CommandText = String.Format("INSERT INTO tabUser (lastName,firstName) VALUES ('{0}','{1}')", user.GetFirstName(), user.GetLastName());
    Cmd.ExecuteNonQuery();

    And now I want to have in:
    int lastId
    the last_insert_rowid().

    Making "SELECT idUser FROM tabUser WHERE sFirstName=firstName AND sLastName=lastName" isn't what I want.

    Thx.

     
    • felix

      felix - 2004-06-11

      Try adding:

      Cmd.CommandText = "SELECT last_insert_rowid()";
      Object o = Cmd.ExecuteScalar();
      int lastID = Convert.ToInt32(o.ToString);

      HTH

       
      • Nobody/Anonymous

        Thank you :-)

        P.

         

Log in to post a comment.