Avatar of wayneray
wayneray
Flag 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.
Microsoft Development.NET Programming

Avatar of undefined
Last Comment
wayneray

8/22/2022 - Mon
Rainer Jeschor

From your excerpt Cmd is not initialized.
wayneray

ASKER
Cmd is also in my public module.
John (Yiannis) Toutountzoglou

Drd= New OleDbDataReader
Drd=Cmd.ExecuteReader

Cmd is also in my public module.
Which Connection are u using with the cmd...?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
wayneray

ASKER
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
John (Yiannis) Toutountzoglou

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

Which Cmd Command ?
Where Is the Select Statement

Command(String,Connection)
ASKER CERTIFIED SOLUTION
John (Yiannis) Toutountzoglou

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
wayneray

ASKER
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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.