Results 1 to 5 of 5

Thread: [RESOLVED] vb net 2010 how to read a single string from a sqlite3 database file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    20

    Resolved [RESOLVED] vb net 2010 how to read a single string from a sqlite3 database file

    After looking everywhere i always come up with the same problem, or its in the wrong programming language or its a broken link.
    so i turn to here hoping someone can help me a little bit.

    what i try to do is the following.

    1. open a local sqlite3 database only for reading
    2. read a specific string in a table called "parts", in the colum named "name" find the value "scaff101" and the get the value of that record in the colum "quan"


    Code:
    (little example of the table to be more clear)
    ##################################################
    #                       Parts                    #
    ##################################################
    # key #   Name    # Type # Length # Width # Quan # 
    ##################################################
    #  1  #  scaff99  #  b1  #  100   #  50   #  30  #
    ##################################################
    #  2  #  scaff100 #  f3  #  250   #  10   #  80  #
    ##################################################
    #  3  #  scaff101 #  h9  #  125   #  25   #  90  #  <-------------
    ##################################################
    #  4  #  scaff102 #  z7  #  550   #  20   #  60  #
    ##################################################
    the only part of this table i'm intrested in is "90" so i dont need anything like writing, changing, deleting, or whatever.

    i'm happy if somebody can show me in the right direction or a little example code to get me started.
    i have the "sqlite-netFx40-setup-bundle-x86-2010-1.0.92.0" installed to have access to the system.data.sqlite.dll and system.data.sqlite.linq.dll
    but on sqlite website i could not find any usefull starting information for a beginner with databasesand i really dont need that much i think

    thank you for your time
    Last edited by The_Lone_Wolf; Apr 8th, 2014 at 04:16 PM. Reason: edited some typos regarding naming of table and column

  2. #2
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: vb net 2010 how to read a single string from a sqlite3 database file

    Never used SQLite but I think the command structure is standard. If that is the case you just need a simple Select statement and ExecuteScalar

    The statement should be something like:
    Code:
    SELECT Quan FROM name WHERE type='scaff101'
    Part of the code
    Code:
    Dim quantity as integer
    Dim conn As New SqliteConnection("Data Source=c:\mydb.db;Version=3;")
    conn.Open()
    Using cmd As New SqliteCommand("SELECT Quan FROM name WHERE type='scaff101'", conn)
        quantity = cmd.ExecuteScalar
    End Using
    Last edited by kaliman79912; Apr 8th, 2014 at 03:31 PM.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  3. #3
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Re: vb net 2010 how to read a single string from a sqlite3 database file

    Your SQL statement would look something like this:
    Code:
    "SELECT Quan FROM tablenamehere WHERE Name = 'scaff101'"
    Or are you looking for the complete code of writing your specific Command and getting a result back into a DataReader and getting the value from it? I hope this will point you into the right direction and you can attempt something and let us know what happened...

  4. #4
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: vb net 2010 how to read a single string from a sqlite3 database file

    I think you misread the OP's statement. The table is named "name" and the column is "type", the correct statement would be

    Code:
    SELECT Quan FROM name WHERE type = 'scaff101'
    He does not need a dataReader, he just needs that one value
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    20

    Re: vb net 2010 how to read a single string from a sqlite3 database file

    Thank you very much it works excatly as i wanted and needed.
    and i want to set a mistake straight. the table name was "parts" i made a typo there.

    when i have time i go deeper in db programming but for now this is what i was searching for.

    thanks again.

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