Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Incorrect syntax near 'T18:'.

Posted on 2011-09-17
2
Medium Priority
?
358 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 84

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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

886 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