Insert Date (vb.net) in SQL database error

Snosky

Member
Joined
Dec 28, 2005
Messages
17
Programming Experience
1-3
I have 2 DateTimePickers on a form

in the form code the following happens
VB.NET:
 Private Sub btnReservation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReserveer.Click
        Dim ReservationAs New ReservationClass
        Dim From_date As Date
        Dim To_date As Date
        From_date = datetimepickerFrom_date.Value
        To_date = datetimepickerTo_date.Value
        reservation.Add_reservation_2(Me.cboOrderID, From_date, To_date, Me.cboAutoID)        
    End Sub
>> reservation class
VB.NET:
 Public Sub Add_reservation_2(ByVal OrderID, ByVal FromDate, ByVal ToDate, ByVal AutoID)
        Dim con1 As New ClaConnectionOrder
        con1.conAdd_in_orderline(OrderID, FromDate, ToDate, AutoID)
    End Sub
>> Connection Class
VB.NET:
 Public Class ClaConnectionOrder
   
    Dim conStr As String = "workstation id=LAPTOP_IMS;packet size=4096;integrated security=SSPI;data source=LAPTOP_IMS;persist security info=False;initial catalog=CARS"
    Dim sqlStr As String = "SELECT * FROM Order_lijn ol, Orders o where ol.Order_ID = o.Order_ID"

    'Connectie object creeeren
    Dim connection As New SqlConnection(conStr)

    'Data adaptor object creeeren
    Dim adapter As New SqlDataAdapter(sqlStr, connection)

    'Dataset creeeren en met data van adaptor vullen
    Dim ds As DataSet = New DataSet
    Dim dv As DataView
    Dim obrow As Data.DataRow
    Dim obds As DataSet = New DataSet
    Dim obbi As SqlClient.SqlCommandBuilder
    Dim customers As DataTable
    Public Sub conOpen()
        adapter.Fill(ds, "Order_line")
        dv = ds.Tables("Order_line").DefaultView
    End Sub

    Public Sub conClose()
        adapter.Dispose()
    End Sub

    Public Sub conAdd_in_orderline(ByVal OrderID As ComboBox, ByVal FromDate As DateTimePicker, ByVal ToDate As DateTimePicker, ByVal AutoID As ComboBox)
        connection.Open()
        Dim sqlStr As String
        sqlStr = "insert into Order_lijn(Order_ID,Auto_ID,Begin_periode, Eind_periode) values ('" & OrderID.SelectedValue & "','" & AutoID.SelectedValue & "', '" & FromDate.Date & "','" & ToDate.Date & "')"
        Dim objCmd As New SqlCommand(sqlStr, connection)
        objCmd.ExecuteNonQuery()
            End Sub
When i click on the button reservation
I get this error :
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: Systemerror.

somebody a solution?

thanx in advance!
 
Just a Guess

I had a similar error and found that the SQL statement took the date in a different format from what I was sending. So you may want to check and make sure the date format is uniform. I analyzed thru the Query Analyzer to find my error.

Hope this helps.
Good Luck!
 
Back
Top