Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Incorrect syntax near 'T18:'.

Posted on 2011-09-17
2
Medium Priority
?
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 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