dcsimg
Results 1 to 5 of 5

Thread: Simple SQLite database question

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,421

    Simple SQLite database question

    Hi everyone, I have just started working with databases and for the most part, I'm clueless. I'm trying to do an INSERT statement and somehow get the results (row with values?).

    Here's the code:
    Code:
           'Declare the main SQLite data access objects
            Dim objConn As New SQLiteConnection
            Dim objCommand As New SQLiteCommand
    
     Try
                objConn = New SQLiteConnection(CONNECTION_STR & "New=True;")
    
                objConn.Open()
    
                objCommand = objConn.CreateCommand()
    
                objCommand.CommandText = "Create TABLE customer(ID Int PRIMARY KEY Not NULL,
                    firstName Text Not NULL, lastName Text Not NULL, phoneNumber Text Not NULL, Birthday Text Not Null);"
                objCommand.ExecuteNonQuery()
    
                objCommand = objConn.CreateCommand()
                objCommand.CommandText = "INSERT INTO customer (ID, firstname, lastName, phoneNumber, birthday)
                VALUES(1, 'Paul', 'Jones', '222-6666', 'May 16 1954');"
    
                dim rowsAffected as Integer = objCommand.ExecuteNonQuery()
    
            Finally
                'close the connection
                If Not IsNothing(objConn) Then
                    objConn.Close()
                End If
            End Try
    Last edited by jumper77; Jun 4th, 2016 at 01:14 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,160

    Re: Simple SQLite database question

    So what actually happens that you don't expect? Is an exception thrown? If so, what is the error message?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,421

    Re: Simple SQLite database question

    Hi jmc, thank you for the reply. As I said, databases are a new creature to me so I'm just trying what I can find by searching on the net.

    What I'm sure I'm missing is some 'basic' concept about what I'm trying to do. I don't get any errors. But I want to get a dataSet that has... well, data. At this point I'm wondering if maybe I should do a 'select' statement outside of the 'createDatabase()' sub.

    If you can point me in a direction, I would really appreciate it.
    thanks

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,160

    Re: Simple SQLite database question

    Well yeah, if you want to get data from the database then you do that with a SELECT statement. INSERT adds new data to the database, UPDATE modifies existing data and DELETES removes existing data. It sounds like you should be doing some basic reading on databases themselves but, as far as ADO.NET operations are concerned, I suggest that you follow the CodeBank link in my signature below and check out my thread on Retrieving & Saving Data. It provides code examples for some of the most common ADO.NET scenarios.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,421

    Re: Simple SQLite database question

    Thank you. I'm getting ready to do a select from the calling function for CreateDatabase. But you're right about reading up. I need to know a lot more before this is over. The whole time I was working I managed to stay away from databases, and after I retired, here I am wanting to learn.

    I'll look at your CodeBank posts and check it out. I'm sure it will do me good.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width