Results 1 to 5 of 5

Thread: VB.Net and SQLite

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    20

    VB.Net and SQLite

    Hi. I created a small program which one uses the SQLite database. I have a simple table employees, composed of the name and password. I can not write sql script correctly. application code is:
    Code:
    Imports System.Data
    Imports System.Data.SQLite
    Code:
    Public Class Form1
    
        Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
            Dim connec = New SQLite.SQLiteConnection()
            Dim myCommand As New SQLite.SQLiteCommand()
            Dim myData As SQLite.SQLiteDataReader
            Dim myAdapter As SQLite.SQLiteDataAdapter
            'Dim SQL As String
    
            Dim name As String = txtUser.Text
            'Dim password As String = txtPassword.Text
    Try
                connec.ConnectionString = "Data Source=" & Application.StartupPath & "\employees.db3; FailIfMissing=True;"
                connec.Open()
                myCommand = connec.CreateCommand
                myCommand.CommandText = "SELECT name FROM user WHERE name = '" + txtUser.Text
                myData = myCommand.ExecuteReader()
                myData.Read()
                If myData.HasRows Then
                    frmmain.Show()
                    Me.Hide()
    
                    myData.Close()
                Else
                    MessageBox.Show("Error")
                    myData.Close()
    
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    please help me in this issue.
    thank you.

  2. #2
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: VB.Net and SQLite

    I don't really understand what you are doing, but i use this to read from a database. it only server as and example, you can get ideas from it.

    vb Code:
    1. Sub loadSettings(byval DBPath as string)
    2.         Dim Names() As String
    3.         Dim Values() As String
    4.         Dim conn As SQLiteConnection = New SQLiteConnection("Data Source=" & DBPath)
    5.         conn.SetPassword(dbPassword)
    6.  
    7.         conn.Open()
    8.         'conn.ChangePassword(vbNullString)
    9.         sSQL = "Select Name,Value From settings"
    10.         Dim cmd As SQLiteCommand = New SQLiteCommand(conn)
    11.         cmd.CommandText = sSQL
    12.         Dim reader As SQLiteDataReader = cmd.ExecuteReader()
    13.         Dim i As Integer = 0
    14.         If reader.VisibleFieldCount > 0 Then
    15.             dicSettings.Clear()
    16.         End If
    17.         Do While (reader.Read())
    18.             ReDim Preserve Names(i)
    19.             ReDim Preserve Values(i)
    20.             Names(i) = reader.Item("name").ToString
    21.             Values(i) = reader.Item("value").ToString
    22.             dicSettings.Add(Names(i), Values(i))
    23.         Loop
    24.         reader.Close()
    25.         conn.Close()
    26.         '// apply the settings //
    27.  
    28.     End Sub
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    20

    Re: VB.Net and SQLite

    Thanks for the reply. I built a form of logging that would open after connecting frmmain. I put a PrtScr.
    Attached Images Attached Images  

  4. #4
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: VB.Net and SQLite

    Here's a good place to start.

    One problem I saw was a missing ending quote.
    Code:
    myCommand.CommandText = "SELECT name FROM user WHERE name = '" + txtUser.Text & "'"
    Also instead of using txtUser.Text you should use parameters. If will save you both time and aggravation.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    20

    Resolved Re: VB.Net and SQLite

    thank you. That was the problem.

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