###Datatype problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I am trying to push the data from my datatable to my database. However i keep getting an error stating

Error converting data type char to datetime

Here is my code
daClient.InsertCommand.Parameters.Add("@RoomID", SqlDbType.Char, 5, "RoomID"
daClient.InsertCommand.Parameters.Add("@RoomDt", SqlDbType.Char, 50, "RoomDt"
daClient.InsertCommand.Parameters.Add("@Req_Session", SqlDbType.Char, 1, Req_Session"
daClient.InsertCommand.Parameters.Add("@Req_Layout", SqlDbType.Char,
50, "Req_Layout"
daClient.InsertCommand.Parameters.Add("@Guests", SqlDbType.Char, 4, "No_Of_Guests"

The RoomDt column is stored as a datetime column in my databas
and the No_Of_Guests column is stored as an Int(4) column in my database

when i tried to change the RoomDt datatype above to:
daClient.InsertCommand.Parameters.Add("@RoomDt", DateTime, "RoomDt"

i still get an error message that says
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dl
Additional information: Cast from string "RoomDt" to type 'Integer' is not valid
 
Hi Bhavna,

They should be prefixed with SqlDbType, such as SqlDbType.DateTime.
You might also try drag&drop the table in question from Server Explorer to
the form - it will generate the code for you.
 
Hello Miha

thank u for your help. I didnt know that you could just drag from the server explorer. :O

The only one problem is that it is inputting the date column as a long format with the time as well
How would i only enter the date only

i.e 25/01/2004 instead of 25/01/2004 12:23:23

Do u know how to do this?
 
Miha
Thx again for your help. I have just read up on the date format and i have found the solution
I used the .toShortDate
 
Back
Top