Solved

Incorrect syntax near 'T18:'.

Posted on 2011-09-17
2
349 Views
Last Modified: 2012-06-21
i get the error "Incorrect syntax near 'T18:'." but im not sure what it means...

Imports Microsoft.VisualBasic
Imports System.Web.Configuration
Imports System.Data.SqlClient

Public Class wall

    Private Shared local As String = WebConfigurationManager.ConnectionStrings("wallConnectionString").ConnectionString

    Shared Function addpost(ByVal post As String) As String

        Using con As New SqlConnection(local)
            Dim cmd As New SqlCommand(Nothing, con)
            Dim username As String = "runnerjp"
            cmd.CommandText = "INSERT into messages (message,username,created) VALUES (@post," & username & "" & DateTime.Now.ToString("o").Substring(0, 23) & ")"
            cmd.Parameters.AddWithValue("@post", post)
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        End Using
    End Function
End Class

Open in new window


error occures here    cmd.ExecuteNonQuery()
0
Comment
Question by:runnerjp2005
2 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36554551
That is probably part of an ISO format date (like 2011-06-05T18:05:03) that SQL doesn't like for some reason.  http://msdn.microsoft.com/en-us/library/ms190977%28v=sql.90%29.aspx  Maybe it isn't matching your column type properly.  I also don't see that T-SQL supports the ISO format.  http://msdn.microsoft.com/en-us/library/ms186724.aspx
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 36554556
username is without quotes ...
but, as you already use parameters, continue doing so:
Imports Microsoft.VisualBasic
Imports System.Web.Configuration
Imports System.Data.SqlClient

Public Class wall

    Private Shared local As String = WebConfigurationManager.ConnectionStrings("wallConnectionString").ConnectionString

    Shared Function addpost(ByVal post As String) As String

        Using con As New SqlConnection(local)
            Dim cmd As New SqlCommand(Nothing, con)
            Dim username As String = "runnerjp"
            cmd.CommandText = "INSERT into messages (message,username,created) VALUES (@post,@username, @created)"
            cmd.Parameters.AddWithValue("@post", post)
            cmd.Parameters.AddWithValue("@username", username)
            cmd.Parameters.AddWithValue("@created", DateTime.Now.ToString("o").Substring(0, 23))
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        End Using
    End Function
End Class

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now