connecting ms access database with vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ash1802
    New Member
    • Oct 2007
    • 1

    connecting ms access database with vb.net

    hello all
    i have a big problem with my system, can anyone help me plz

    there`s some kind of error, there are 2 text box on my interface, 1 for entering an account number and one for entering password, there is a login button also.

    here is the code when clicking on the button but it does not work!!! plz [code=vb]helpPrivate Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    Dim connection As New OleDb.OleDbConn ection

    Dim command As New OleDbCommand
    Dim DataReader1 As OleDbDataReader
    Dim selectall As String
    Dim Account_No As String = txtAccount.Text
    Dim Password As String = txtPassword.Tex t
    connection = New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0; Datasource=db1. mdb")

    selectall = "select * FROM Security WHERE A/c_number= " & Account_No & " and Password = " & Password & ""
    command = New OleDbCommand(se lectall, connection)
    connection.Open ()
    DataReader1 = command.Execute Reader()
    If DataReader1.Has Rows Then
    MessageBox.Show ("ok")
    Else
    MessageBox.Show ("incorrect Account_No or password")
    End If

    End Sub
    End Class[/code]
    Last edited by pbmods; Oct 22 '07, 11:57 AM. Reason: Added CODE tags.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Do you get an error? Which line number?

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      You would probably also have to give a better path to your mdb file then just "db1.mdb", if it errors there you should probably give a full path?

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Maybe selectall = "select * FROM Security WHERE A/c_number= ' " & Account_No & " ' and Password = ' " & Password & " ' " will help also, if there is no error. HTH.

        Comment

        • bhar
          Banned
          New Member
          • Apr 2006
          • 37

          #5
          Hi,

          Working with the OleDbConnection object is similar to using the SqlConnection object. However, because the OleDb.NET data provider can be used to connect to several types of databases, you must specify a provider name in the connection string. These provider names will be the same ones that were used with earlier versions of ADO. Here is an example of a connection string for a Microsoft Access database:

          [code=vb]
          Dim myConn As OleDbConnection =New OleDbConnection ()

          myConn.Connecti onString="Provi der=Microsoft.J et.OLEDB.4.0; Data Source=C:\data\ northwind.mdb; User ID=guest; Password=p5n65"
          [/code]

          If you are working in Visual studio.NET, a reference will automatically be set to the System.Data.dll for most project types. If not, you must add this reference manually. The System.Data.dll assembly supports both System.Data.Sql Client and System.Data.Ole Db. If you install teh ODBC data provider or any other third-party providers, you will have to set references to teh appropriate assemblies.


          hope this helps.<Advertis ing link removed>
          Last edited by pbmods; Oct 22 '07, 11:57 AM. Reason: Added CODE tags.

          Comment

          Working...