Solved

Incorrect syntax near 'T18:'.

Posted on 2011-09-17
2
346 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 82

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

13 Experts available now in Live!

Get 1:1 Help Now