G
Guest
Hi
Having trouble filling a datetime filed in SQL table with a value from an
array.
The original source is a comma-delimited text file where the date and time
values are in two columns. I require to combine the two colums into one
datetime field in the SQL table
Here is what I am doing
FileOpen(1, my_file_to_validate, OpenMode.Binary)
MyArray = New String(My_RecordCount - 1, 38) {}
For row = 0 To My_RecordCount - 1
myrecord = LineInput(1)
Dim x = Split(myrecord, ",")
Dim MyItemDate as Date
MyItemDate = New Date(Microsoft.VisualBasic.Left(x(3), 4), _
Microsoft.VisualBasic.Mid(x(3), 5, 2), _
Microsoft.VisualBasic.Right(x(3), 2), _
Microsoft.VisualBasic.Left(x(2), 2), _
Microsoft.VisualBasic.Mid(x(2), 3, 2), _
Microsoft.VisualBasic.Mid(x(2), 5, 2))
MyArray_Array(row, 2) = CallDate
The above opens the text file and populates the array
....and when that is completed the following is supposed to take the date
value from array and insert it into the SQL table .... BUT ..... I receive
errors at the "myCommand.ExecuteNonQuery()" line indiacting that the value
cannot be accepted because it is not the right format and cannot be converted.
For i = 0 To UBound(MyArray)
myConnection = New SqlConnection _
("Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|" _
+ "\Beta_MyInfo.mdf;Integrated Security=True;User
Instance=True")
myConnection.Open()
insertCMD = "Insert into MyLog (Date) values ('" &
MyArray(i, 2) & "');"
myCommand = New SqlCommand(insertCMD, myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close()
Next
Any ideas where I might be going wrong
Thanks
Michael Bond
Having trouble filling a datetime filed in SQL table with a value from an
array.
The original source is a comma-delimited text file where the date and time
values are in two columns. I require to combine the two colums into one
datetime field in the SQL table
Here is what I am doing
FileOpen(1, my_file_to_validate, OpenMode.Binary)
MyArray = New String(My_RecordCount - 1, 38) {}
For row = 0 To My_RecordCount - 1
myrecord = LineInput(1)
Dim x = Split(myrecord, ",")
Dim MyItemDate as Date
MyItemDate = New Date(Microsoft.VisualBasic.Left(x(3), 4), _
Microsoft.VisualBasic.Mid(x(3), 5, 2), _
Microsoft.VisualBasic.Right(x(3), 2), _
Microsoft.VisualBasic.Left(x(2), 2), _
Microsoft.VisualBasic.Mid(x(2), 3, 2), _
Microsoft.VisualBasic.Mid(x(2), 5, 2))
MyArray_Array(row, 2) = CallDate
The above opens the text file and populates the array
....and when that is completed the following is supposed to take the date
value from array and insert it into the SQL table .... BUT ..... I receive
errors at the "myCommand.ExecuteNonQuery()" line indiacting that the value
cannot be accepted because it is not the right format and cannot be converted.
For i = 0 To UBound(MyArray)
myConnection = New SqlConnection _
("Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|" _
+ "\Beta_MyInfo.mdf;Integrated Security=True;User
Instance=True")
myConnection.Open()
insertCMD = "Insert into MyLog (Date) values ('" &
MyArray(i, 2) & "');"
myCommand = New SqlCommand(insertCMD, myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close()
Next
Any ideas where I might be going wrong
Thanks
Michael Bond