Solved

Incorrect syntax near 'T18:'.

Posted on 2011-09-17
2
353 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 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 143

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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