Solved

MS Access with ADO.NET in VB.NET

Posted on 2003-11-16
5
941 Views
Last Modified: 2010-04-17
Hi,

I am trying to write a simple login screen where the code takes the name entered by the user and password in  a textbox and does an sql query to see if the database has it. I am using Access. The funny thing is that when I say select * from Login, it works with out an error. The error is An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Please Help, I am stumped.
Thanks


I have a Connection class.

The Connection code is :

Option Explicit On
'Option Strict
Imports System
Imports System.Data
Imports System.Data.OleDb
Namespace DBConnection
    Public Class DBConnect

        Dim ConnectString As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
                                                   "data source=C:\OmniTest\Test.mdb;"
        Dim myConnection As New OleDbConnection(ConnectString)
        Dim objCmd As OleDbCommand
        Dim objReader As OleDbDataReader
        Dim ds As DataSet

        Public Sub New()
            myConnection.Open()
        End Sub

        Public Function getDataSet(ByVal SqlSelect As String) As DataSet

            Dim myDataAdapter As New OleDbDataAdapter(SqlSelect, myConnection)
            Dim myDataSet As New DataSet()
            myDataAdapter.Fill(myDataSet)
            ds = myDataSet
            Return myDataSet
        End Function

        Public Function getDataReader(ByVal SqlSelect As String) As OleDbDataReader
            objCmd = New OleDbCommand(SqlSelect, myConnection)
            Return objCmd.ExecuteReader()
        End Function

        Public Function doUpdate(ByVal SqlManipulate As String) As Integer
            objCmd = New OleDbCommand(SqlManipulate, myConnection)
            Return objCmd.ExecuteNonQuery()
        End Function

        Public Function getRow(ByVal ds As DataSet, ByVal row As Integer) As DataRow
            Dim objTable As DataTable = ds.Tables(0)
            Return objTable.Rows(row)
        End Function

        Public Function getField(ByVal FieldName As String, ByVal I As Integer) As VariantType
            Dim objRow As DataRow
            Dim objTable As DataTable = ds.Tables(0)
            objRow = objTable.Rows(I)
            Return objRow(FieldName)
        End Function

        Protected Overrides Sub Finalize()
            myConnection.Close()
        End Sub

    End Class

End Namespace


The code on my button click is:

         Dim name As String = txtUser.Text
        MsgBox(name)
        Dim pwd As String = txtPwd.Text
        MsgBox(pwd)
        SQLString1 = "SELECT Username, Password FROM Login WHERE Username=" + name
         objDBConnect.getDataSet(SQLString1)

I even tried:

Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
                                   "data source=C:\OmniTest\Test.mdb;"
        Dim objConnection As New OleDbConnection(strConnection)
        objConnection.Open()
        MsgBox("Open")

        Dim strSQL As String = "SELECT Username, Password FROM Login WHERE Username = " + name
        Dim objAdapter As New OleDbDataAdapter(strSQL, objConnection)
        Dim objDataSet As New DataSet()
        objAdapter.Fill(objDataSet, "Login")
        Dim Login As DataTable = objDataSet.Tables("Login")
       

        objConnection.Close()

0
Comment
Question by:PhillyZoo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 9758645
You need to surround the content of the variable with queotes:

Dim strSQL As String = "SELECT Username, Password FROM Login WHERE Username = '" + name + "'"
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9759870
will you close that one too?
0
 

Author Comment

by:PhillyZoo
ID: 9759884
Yes, thanks
0
 

Author Comment

by:PhillyZoo
ID: 9759887
I knew it was something small that I was forgeting. For some reason I thought that only numbers needed the quotes around the parameter.

Have a Good Day
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9760095
>>For some reason I thought that only numbers needed the quotes around the parameter.

Numbers do not need to quotes. Strings need quotes. Dates needs #.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn different types of Android Layout and some basics of an Android App.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question