Convert C# DateTime to SQL DateTime

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span>Hello! I am having a big problem when i try to save DateTime.Today.Date to my SQL database. It gives me an error "<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:15px; line-height:16px <em style=" Conversion failed
when converting date and/or time from character string[/i]<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:15px; font-weight:bold; line-height:16px <em style=" .[/i]<span>" Then ive tryed this <span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:13px; line-height:16px DateTime.Today.ToShortTimeString()
and it works but it gives me the the wrong date <span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:13px; line-height:16px 1.1.1900. ive tryed converting it but with no results. Pls help, ty!

<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:x-small <span style="line-height:16px veza.Open();
<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:x-small <span style="line-height:16px string otvori = "INSERT INTO tblPredbiljezba ([ime],[prezime],[adresa],,[telefon],[datum],[seminar])
VALUES (" + txtIme.Text + "," + txtPrezime.Text + ", " + txtAdresa.Text + ", " + txtEmail.Text + ", " + txtTelefon.Text + "," +
[i] <span style="text-decoration:underline DateTime.Today.ToShortTimeString() [/i] + ", " + GridView1.SelectedRow.Cells[1].Text + ")";
<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:x-small <span style="line-height:16px SqlCommand ubaci = new SqlCommand(otvori, veza);
<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:x-small <span style="line-height:16px ubaci.ExecuteNonQuery();
<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:x-small <span style="line-height:16px veza.Close();

<span style="color:#313c46; font-family:Arial,Helvetica,sans-serif; font-size:13px; line-height:16px <br/>


[url=http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2e93eefe-aa26-4f25-8d84-c80f71469942]View the full article[/url]
 
Back
Top