Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Object reference not set to an instance of an object.

Object reference not set to an instance of an object.

Scheduled Pinned Locked Moved Visual Basic
helpcom
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saqib Jabbar
    wrote on last edited by
    #1

    Public Class form_login Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click Get_Data() End Sub Public Sub Get_Data() Dim qty As String Dim cons As String qty = "SELECT * FROM LOGIN WHERE USER_ID = @USER_ID AND PASSWORD = @PASSWORD" cons = "Provider=Microsoft.Jet.OLEDB.4.0;data source=login.mdb" Dim con As New OleDbConnection() con.ConnectionString = cons Dim com As New OleDbCommand() com.CommandText = qty Dim da As New OleDbDataAdapter() da.SelectCommand.Parameters.AddWithValue("@USER_ID", txt_user_id.Text)--------error occurs on this line---- da.SelectCommand.Parameters.AddWithValue("@PASSWORD", txt_password.Text) Dim dt As New DataTable da.Fill(dt) If dt.Rows.Count > 0 Then Success.user_id = dt.Rows(0)("USER_ID").ToString Me.Hide() Success.Show() End If End Sub End Class Please help me out of thhis

    D J 2 Replies Last reply
    0
    • S Saqib Jabbar

      Public Class form_login Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click Get_Data() End Sub Public Sub Get_Data() Dim qty As String Dim cons As String qty = "SELECT * FROM LOGIN WHERE USER_ID = @USER_ID AND PASSWORD = @PASSWORD" cons = "Provider=Microsoft.Jet.OLEDB.4.0;data source=login.mdb" Dim con As New OleDbConnection() con.ConnectionString = cons Dim com As New OleDbCommand() com.CommandText = qty Dim da As New OleDbDataAdapter() da.SelectCommand.Parameters.AddWithValue("@USER_ID", txt_user_id.Text)--------error occurs on this line---- da.SelectCommand.Parameters.AddWithValue("@PASSWORD", txt_password.Text) Dim dt As New DataTable da.Fill(dt) If dt.Rows.Count > 0 Then Success.user_id = dt.Rows(0)("USER_ID").ToString Me.Hide() Success.Show() End If End Sub End Class Please help me out of thhis

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      Have you tried to change the constructor for the data adapter to; Dim da as New OleDbDataAdapter(qty,cons) Which would negate the need for con or com OR

      dim com as NewOleDbCommand
      com.connection = con
      Dim da as New OleDbDataAdapter(com)

      Just think your referencing and constructors need a tidy up and the problem will be fixed.

      Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

      S 2 Replies Last reply
      0
      • S Saqib Jabbar

        Public Class form_login Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click Get_Data() End Sub Public Sub Get_Data() Dim qty As String Dim cons As String qty = "SELECT * FROM LOGIN WHERE USER_ID = @USER_ID AND PASSWORD = @PASSWORD" cons = "Provider=Microsoft.Jet.OLEDB.4.0;data source=login.mdb" Dim con As New OleDbConnection() con.ConnectionString = cons Dim com As New OleDbCommand() com.CommandText = qty Dim da As New OleDbDataAdapter() da.SelectCommand.Parameters.AddWithValue("@USER_ID", txt_user_id.Text)--------error occurs on this line---- da.SelectCommand.Parameters.AddWithValue("@PASSWORD", txt_password.Text) Dim dt As New DataTable da.Fill(dt) If dt.Rows.Count > 0 Then Success.user_id = dt.Rows(0)("USER_ID").ToString Me.Hide() Success.Show() End If End Sub End Class Please help me out of thhis

        J Offline
        J Offline
        JoeSharp
        wrote on last edited by
        #3

        hi set the connection object 'con' to the command object e.g com.Connection = con do not forget to close the connection e.g. con.Close() aftre the dt.Fill(dt) call. regards

        1 Reply Last reply
        0
        • D DaveAuld

          Have you tried to change the constructor for the data adapter to; Dim da as New OleDbDataAdapter(qty,cons) Which would negate the need for con or com OR

          dim com as NewOleDbCommand
          com.connection = con
          Dim da as New OleDbDataAdapter(com)

          Just think your referencing and constructors need a tidy up and the problem will be fixed.

          Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

          S Offline
          S Offline
          Saqib Jabbar
          wrote on last edited by
          #4

          Ur ans was CoOl But if fix the Data Adapter Then It will show another exception in da.fill(dt) //Could not find file 'D:\Login\Login\Login\bin\Debug\login.mdb'.

          E D 2 Replies Last reply
          0
          • S Saqib Jabbar

            Ur ans was CoOl But if fix the Data Adapter Then It will show another exception in da.fill(dt) //Could not find file 'D:\Login\Login\Login\bin\Debug\login.mdb'.

            E Offline
            E Offline
            Estys
            wrote on last edited by
            #5

            See here You should put your connectionsstrings in your app.config

            1 Reply Last reply
            0
            • S Saqib Jabbar

              Ur ans was CoOl But if fix the Data Adapter Then It will show another exception in da.fill(dt) //Could not find file 'D:\Login\Login\Login\bin\Debug\login.mdb'.

              D Offline
              D Offline
              DaveAuld
              wrote on last edited by
              #6

              Your data source property in the connection string is being locally referenced to the working directory. You need to fully qualify the file name and path in this setting to ensure it is correctly found. data source=login.mdb change to data source=x:\thefolderpath\morepath\login.mdb

              Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

              1 Reply Last reply
              0
              • D DaveAuld

                Have you tried to change the constructor for the data adapter to; Dim da as New OleDbDataAdapter(qty,cons) Which would negate the need for con or com OR

                dim com as NewOleDbCommand
                com.connection = con
                Dim da as New OleDbDataAdapter(com)

                Just think your referencing and constructors need a tidy up and the problem will be fixed.

                Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                S Offline
                S Offline
                Saqib Jabbar
                wrote on last edited by
                #7

                thx daveauld I fix iT!?? Thx ALot!?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups