this is what is do to insert data to the Booktbl
Dim MyDate As Datetime = Now()
strAuthor = tbAuthor.Text.Trim
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
Dim myCommand As New SqlCommand("INSERT INTO Booktbl (Author, Date) VALUES(@author,@MyDate)", myConnection)
myCommand.parameters.add("@author",sqldbtype.varchar).value=strAuthor
myCommand.parameters.add("@MyDate",sqldbtype.datetime).value=MyDate
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Catch ex As SqlException
lblMsg.Text = " Error"
End Try
End Sub
After that the date record store in database look like this " 2/22/2006 11:40:40 AM"
the data type used to declare in the Date column is DateTime
this is what i do to retrive Author data depend on the Date
Dim Author As String
Dim no As DateTime
no = "2/22/2006"
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
Dim myCommand As New SqlCommand("SELECT Author FROM Booktbl WHERE Date = @no", myConnection)
myCommand.Parameters.Add("@no", SqlDbType.DateTime).Value = no
myConnection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
myReader.Read()
Author = myReader("Author")
myReader.Close()
myConnection.Close()
lblShow2.Text = Author
it show me the error message "Invalid attempt to read when no data is present" why? it seem like the date got problem. i been working on this since few days, yet i still can't get the result. anyone help appreaciate
This post has been edited by doublek: Feb 22 2006, 09:34 PM
Date error -asp.net