Note that there are some explanatory texts on larger screens.

plurals
  1. POvb.net SQL date to time conversion issue
    primarykey
    data
    text
    <p>The error is: Conversion failed when converting date and/or time from character string.</p> <p>Basically I'm trying to make it so that when someone clicks a location in a list box it increments the correct field in a Stats table by 1 to say that they clicked the location. I've been trying to solve this for a while now and can't get anywhere. My date is in date format, and so is the Date field in my Stats table. My code can be seen below.</p> <pre><code> Dim Current As String Dim Check As String Dim objCmd2 As Object Dim iCount As Integer Dim tDate As Date Current = LocBox.SelectedItem Check = LocList.FindString(Current) If Check &gt; -1 Then MsgBox("You have already selected this place to visit") Else LocList.Items.Add(Current) ObjDataReader.Close() tDate = Date.Today MessageBox.Show(tDate) tDate = tDate.ToString() objCmd2 = New SqlCommand("SELECT " &amp; Replace(Current, " ", "_") &amp; " FROM Stats WHERE Date = '" &amp; tDate &amp; "'", objConn) ObjDataReader = objCmd2.ExecuteReader If ObjDataReader.HasRows Then ObjDataReader.Read() If ObjDataReader(0) Is DBNull.Value Then iCount = 0 Else iCount = ObjDataReader(0) End If Else iCount = 0 End If objCmd = New SqlCommand("INSERT INTO Stats(Date," &amp; Replace(Current, " ", "_") &amp; ") Values('" &amp; tDate.Date &amp; "'," &amp; iCount &amp; " )", objConn) ObjDataReader.Close() objCmd.ExecuteNonQuery() objConn.Close() </code></pre> <p>Thanks in advance.</p> <p>The issue comes in with the second SQL statement I think. I don't understand why adding a date into a date field would be an issue, I've tried adding it as a string which didn't work. Thanks for all the answers so far.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload