Share via


The given value of type String from the data source cannot be converted to type datetime of the specified target column.

Question

Wednesday, May 19, 2010 3:35 AM

I have this error "The given value of type String from the data source cannot be converted to type datetime of the specified target column." when I used sqlbulkcopy to do the transaction

Here is my code:

Dim id As String = gvData.DataKeys(gvr.RowIndex).Value.ToString
                        'compare with the id in DataTable or others

              intRetValue = WebService.AddEvent(dtDataTable.Rows(gvr.RowIndex).Item("EventID").ToString(), dtDataTable.Rows(gvr.RowIndex).Item("startDate").ToString(), dtDataTable.Rows(gvr.RowIndex).Item("EndDate").ToString()))

my startDate and EndDate are of type datetime in the sql..

Thanks!

All replies (4)

Wednesday, May 19, 2010 4:18 AM âś…Answered

Hi,

I think the problem is that in data table you have datetime as string and you inserting that in date time in sql server.

Store date time format in data table and it will work.

Cheers,


Wednesday, May 19, 2010 4:12 AM

Hi

It seems that you are reading data from the DataTable and inserting to the database. What is the format of the data in startDate and endDate columns in Data Table? Make sure it is compatible with the default format of the SQL Server.


Thursday, May 20, 2010 4:03 AM

Hi. So I have changed the data table to the following

DataRow("StartDate") = CType(Trim(reader("Date of Event").ToString), Date)
DataRow("EndDate") = CType(Trim(reader("Date of Event").ToString), Date)

Is it Date or DateTime? Are they the same?

In addition, may i know if say I have a string like this "29 Jul 2009 (Morning)" in the excel file, how do I extract the date out from this string and stored in the DataRow("StartDate") ?

Thanks!


Friday, April 15, 2011 8:48 AM

If the table having autonumber column, then u need to add a column (of type integer) to your Dataset or Datatable

 

Cheers,

Ganesh