Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim ConnectionString As String = "Data Source= (LocalDB)\MSSQLLocalDB"
Dim Connection As New SqlConnection(ConnectionString)
Connection.Open()
Dim Command As New SqlCommand("SELECT * FROM Table")
Dim Reader As SqlDataReader
Reader = Command.ExecuteReader()
Dim DT As New DataTable()
DT.Load(Reader)
Connection.Close()
ReservationsDVG.DataSource = DT


This throws an exception error saying that reader hasn't been initialised
Posted
Comments
Richard MacCutchan 11-May-15 5:03am    
That probably means that your select clause did not return anything. You should add some proper error checking in your code to test the results of any statement that could fail.

1 solution

Link Connection to Command...Currently Command does not know on hat connection to execute the query, so no reader created...
VB
Commnad.Connection = Connection
Reader = Command.ExecuteReader()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900