Link to home
Start Free TrialLog in
Avatar of wayneray
waynerayFlag for United States of America

asked on

Creating a datareader Causes an error

I am new to vb.net and having fun learning. My Drd variable is declared public in my module. When I run this code. I get the error, "Object reference not set to an instance of an object."

Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        Dim fname As String = txtFName.Text
        Dim lname As String = txtLName.Text
        Dim odt As Date = dtNurse.Value
        Dim symp As String = lstSymptom.SelectedItem
        Dim observ As String = txtAction.Text

        CurrentRow = 0

        Cnn.Open()

        Dad = New OleDbDataAdapter("SELECT Student_UID FROM tblElemStudents where First_Name = '" & fname.Replace("'", "''") & _
                                   "' and Last_Name = '" & lname.Replace("'", "''") & "'", Cnn)

        Dad.Fill(Dst, "Student_UID")
       


        Drd = Cmd.ExecuteReader

Everything runs fine up to the last line of code above. What am I doing wrong?

Thanks in advance.
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

From your excerpt Cmd is not initialized.
Avatar of wayneray

ASKER

Cmd is also in my public module.
Drd= New OleDbDataReader
Drd=Cmd.ExecuteReader

Cmd is also in my public module.
Which Connection are u using with the cmd...?
cnn is my connection and it is put in my module. Here is my module code.

Module Module1


    Public Cnn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Panama School\Apps\ppsMed.accdb")

    Public Dad As OleDbDataAdapter

    Public Drd As OleDbDataReader

    Public Cmd As OleDbCommand

    Public Dst = New DataSet

    Public CurrentRow As Integer

    Public Suid As String


End Module
You have
Public Cmd As OleDbCommand
and
 Drd = Cmd.ExecuteReader

Which Cmd Command ?
Where Is the Select Statement

Command(String,Connection)
ASKER CERTIFIED SOLUTION
Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry I misunderstood your question. I was trying use the dataadpter as my command and was way off base. I did not have my cnn command instance set. Thanks for helping this newbie. Stick around I am sure I will put out some new questions. I do appreciate your patience.