Reading Data From SQL
Hi Guys,
I am wondering if somone could help me with this?
I have a problem reading some data from an SQL Database.
I need Date.Today and some other text from the Database because. I am making a digital Agenda that shows todays tasks.
Code:
Dim myDataReader As SqlDataReader
Dim mySqlConnection As SqlConnection
Dim mySqlCommand As SqlCommand
mySqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
mySqlCommand = New SqlCommand("Select ItemID, TimeStamp, TimeText, Heading From Items WHERE DateStamp='" & Date.Today & "' AND OwnerKey='" & Request.Cookies("KappersUnlimited_Username").Value & "' ORDER BY TimeText", mySqlConnection)
mySqlConnection.Open()
myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.CloseCo nnection)
Do While (myDataReader.Read())
If myDataReader.Item("TimeStamp") = "9" Then
TestLink9.Text = myDataReader.Item("TimeText") & " " & "-" & " " & myDataReader.Item("Heading")
End If
If (myDataReader.IsDBNull(0)) Then
TestLink9.Text = ""
Else
TestLink9.Text = "No Item found"
End If
'---------------------------------------------------------
If myDataReader.Item("TimeStamp") = "10" Then
TestLink9.Text = myDataReader.Item("TimeText") & " " & "-" & " " & myDataReader.Item("Heading")
End If
If (myDataReader.IsDBNull(0)) Then
TestLink10.Text = ""
Else
TestLink10.Text = myDataReader.Item("TimeStamp")
End If
'------------------------------------------------------
etc.....
The Problem discription:
When i have no records i receive the following error:
Invalid to read when no data is present.(Tried too reslove this but no success).
Second(When all records are present):
It seems that the SqlDataReader is not attempting to read all data.
I tried Datasets, SqlDataAdaptersand Tables.
This is an ASP.NET website using SQL Server and to bin data i am now using Linkbuttons.
Thanks for your help.
|