Results 1 to 4 of 4

Thread: vbRichClient Create Table AUTO_INCREMENT

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    486

    vbRichClient Create Table AUTO_INCREMENT

    Hello,

    Finally working with the vbrichclient SQL lite stuff ( never thought I would)...

    Really Awesome framework.

    I am able to create the table in a DB (file) I need and fill it with data, but in my case I need the ID/ primary key to be auto generated.

    so when I do the .setInt32, or on the creating of the table how do I make it so the ID field is automatically generated?

    Thanks

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    486

    Re: vbRichClient Create Table AUTO_INCREMENT

    Think I found it, call LastInsertAutoID on cConnection Object?

    WP

  3. #3
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,452

    Re: vbRichClient Create Table AUTO_INCREMENT

    SQLite tables automatically create a field called "rowid" (unless WITHOUT ROWID) is specified that acts as a unique # for each row. Alternately, you can create your own autonumber column by declaring the field with INTEGER PRIMARY KEY keywords (e.g. CREATE TABLE mytable (myfield INTEGER PRIMARY KEY).

    You don't need to set the value for these fields with SetInt32 or anything - just leave it out of any INSERT/UPDATE statements/commands and a # will be generated automatically.

    See here for more info: https://sqlite.org/lang_createtable.html#rowid

  4. #4
    Hyperactive Member
    Join Date
    Jul 2013
    Posts
    400

    Re: vbRichClient Create Table AUTO_INCREMENT

    Adding to what jbpro said:

    by declaring "myfield INTEGER PRIMARY KEY", myfield become just an alias to the internal "rowid".
    by declaring "myfield INTEGER PRIMARY KEY AUTOINCREMENT", sqlite guaranties that every new row will have a rowid that was never used before in that table.
    Carlos

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width