Object reference not set to an instance of an object.
-
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
-
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
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 ORdim 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
-
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
-
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 ORdim 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
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'.
-
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'.
-
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'.
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
-
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 ORdim 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
thx daveauld I fix iT!?? Thx ALot!?