Handling Dates....

C

Child

I am trying to insert some data into a table and keep gettting the error:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM.

Its me testing the database so the dates should be dates. In the CodeBehind
page of the form that calls this AddEvent function I have tried converting
the txtStartDate.Text to a CDate to pass to this function, but same error.
Is there something obvious i am missing?

function to insert data below, other code upon request:

Public Shared Function AddEvent(ByVal AnEvent As anEvent) As Boolean

Dim sInsert As String = "Insert into tblEvents (EventName, Location,
StartDate, EndDate, Address, City, State, Zip, Phone, ContactName,
ContactPhone, ContactEmail, RoomRate, ReservationCode, Additional, Status,
DateOpened) " _

& "values(" _

& "@EventName, @Location, @StartDate, @EndDate, @Address, @City, @State,
@Zip, @Phone, @ContactName, @ContactPhone, @ContactEmail, @RoomRate,
@ReservationCode, @Additional, @Status, @DateOpened)"

Dim conEvents As New SqlConnection

conEvents.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")

Dim cmdEvents As New SqlCommand(sInsert, conEvents)

cmdEvents.Parameters.Add("@EventName", AnEvent.EventName)

cmdEvents.Parameters.Add("@Location", AnEvent.Location)

cmdEvents.Parameters.Add("@DateStart", AnEvent.StartDate)

cmdEvents.Parameters.Add("@DateEnd", AnEvent.EndDate)

cmdEvents.Parameters.Add("@Address", AnEvent.Address)

cmdEvents.Parameters.Add("@City", AnEvent.City)

cmdEvents.Parameters.Add("@State", AnEvent.State)

cmdEvents.Parameters.Add("@Zip", AnEvent.Zip)

cmdEvents.Parameters.Add("@pHONE", AnEvent.Phone)

cmdEvents.Parameters.Add("@ContactName", AnEvent.ContactName)

cmdEvents.Parameters.Add("@ContactPhone", AnEvent.ContactPhone)

cmdEvents.Parameters.Add("@ContactEmail", AnEvent.ContactEmail)

cmdEvents.Parameters.Add("@RoomRate", AnEvent.RoomRate)

cmdEvents.Parameters.Add("@ReservationCode", AnEvent.ReservationCode)

cmdEvents.Parameters.Add("@Additional", AnEvent.Additional)

cmdEvents.Parameters.Add("@Status", AnEvent.STatus)

cmdEvents.Parameters.Add("@DateOpened", AnEvent.DateOpened)

cmdEvents.Parameters.Add("@DateClosed", AnEvent.Dateclosed)

conEvents.Open()

AddEvent = True

Try

cmdEvents.ExecuteNonQuery()

Catch e As SqlException

AddEvent = False

End Try

conEvents.Close()

End Function
 
G

Guest

Your SQL statement is using @StartDate but you are trying to add a parameter
called @DateStart.

Change your code to this:

cmdEvents.Parameters.Add("@StartDate", AnEvent.StartDate)
 
C

Child

Jorge L Matos said:
Your SQL statement is using @StartDate but you are trying to add a
parameter
called @DateStart.


DOH, Jorge, my unborn child is sapping all my brains. I thank you
ETERNALLY.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top