Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want a solution Object reference not set to an instance of an object

Dim connstring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As New SqlConnection(connstring)
conn.Open()
Dim cmd As New SqlCommand("select * from Table_1 where date_register = #" & TextBox1.Text & "#", conn)
Dim myreader As SqlDataReader
'If Not (myreader.IsDBNull(myreader.GetOrdinal("date_register"))) Then
Dim datereg As DateTime = myreader("date_register")
TextBox1.Text = datereg.ToString("MM/dd/yyyy")
'Else
'    TextBox1.Text = ""
'End If
conn.Close()

enter image description here

Hello, is there a solution for the error, thank you

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You did not execute your SQL command and before loading data into your data reader variable, you are trying to use it which is causing that error. Simply do this:

Dim myreader As SqlDataReader = cmd.ExecuteReader
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading