Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
VB
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click

    Dim medate As String = TextBox1.Text
    Dim st As String = ConfigurationManager.ConnectionStrings("testingConnectionString").ToString
    Dim con As New Data.SqlClient.SqlConnection(st)
    con.Open()
    Dim q As String = "insert into mytest values('" & medate & "')"
    Dim com As New Data.SqlClient.SqlCommand(q, con)
    com.ExecuteNonQuery()
    con.Close()
End Sub


I got the following error :-
Conversion failed when converting datetime from character string.


Can any one tell what is the default date format for storage in sql server 2005 ...
When ever my day value increases 12 i get error i m stuck up in very important part please help ... Thanks
Posted
Updated 13-May-11 0:10am
v2
Comments
Ashishmau 13-May-11 5:05am    
why u r storing date as a string...
use datetime only to avoid any problems...
adilmemon 13-May-11 6:09am    
how to convert say me
n i want time as 0:00
as i need to work with date only when i retrive
Ashishmau 13-May-11 6:16am    
Have u ever studied date conversion in sql server from net..if not then study that first..u will get ur soln
m@dhu 13-May-11 5:12am    
Writing everything in caps is called shouting. Use caps wherever necessary.
adilmemon 13-May-11 6:07am    
sorry sir but i wrote in caps the important thing

You can do the following
VB
Dim medate As New DateTime
TextBox1.Text = System.DateTime.Today.Date
       medate = DateTime.Parse(TextBox1.Text)
'or medate can have your date of format mm/dd/yyyy
    Dim q As String = "insert into mytest values('" & medate & "')"
 
Share this answer
 
Comments
adilmemon 13-May-11 6:11am    
but when i format in mm/dd/yyyy i got same error
CAN ANY1 TELL WHAT IS THE DEFAULT DATE FORMAT FOR STORAGE IN SQL SERVER 2005
SQL Server Date Time Format[^]

Always use DateTime datatype for date values and use parameterized query.
 
Share this answer
 
try this,

Dim medate As Date = Date.Parse(TextBox1.Text.ToString())
 
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