Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I am getting the error "the conversion of a char data type to a datetime data type resulted in an out-of-range datetime value in asp.net" when i insert date value into table.

aspx.code
---------
VB
 Private [date] As String = DateTime.Now.ToString

StrQry = ""
            Conn.Open()
            StrQry = "insert into csproject(projectname,projectcode,duration,CreatedBy,CreatedDate) values ('" & txtProjName.Text & "','" & txtProjCode.Text & "','" & Session("EmpNo") & "','" & [date] & "')"
Cmd.Connection = Conn
Cmd.CommandText = StrQry
Cmd.ExecuteNonQuery()
Cmd.Dispose()
Conn.Close()

What is the problem here...

My "CreatedDate" column datatype is datetime.


pls. help

Regards,
Ganesh.S
Posted
Updated 29-Jun-11 21:09pm
v2

Hello,

You are entering one value less.Duration data is not present in values

thanks
sanjeev
 
Share this answer
 
Comments
gani7787 30-Jun-11 3:09am    
Hi,

I am getting the error "the conversion of a char data type to a datetime data type resulted in an out-of-range datetime value in asp.net" when i insert date value into table.

aspx.code
---------
Private [date] As String = DateTime.Now.ToString

StrQry = ""
Conn.Open()
StrQry = "insert into csproject(CreatedDate) values ('" & [date] & "')"
Cmd.Connection = Conn
Cmd.CommandText = StrQry
Cmd.ExecuteNonQuery()
Cmd.Dispose()
Conn.Close()

What is the problem here...

My "CreatedDate" column datatype is datetime.


pls. help

Regards,
Ganesh.S
Private [date] As String = DateTime.Now.ToString


instead you use this,

Private [date] As DateTime = DateTime.Now.ToString


Thank You
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900