.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

incorrect syntax near '4'.

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :

i want to create a table which takes name as from text box in which there will be employee id.. so that it will create table of employee ID. but wen i give any integer in text box and click create it give me an error.. as "Incorrect Syntax near '4'." here 4 is the value which i entered in the text box. if i pass any string or name.. it creats a table of that  string as name with out any error.. but it dose not take integer as name.. plz help am posting m code here.. 

Private Sub Tab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tab.Click

        If con.State = ConnectionState.Open Then


        End If

        con = New SqlConnection("Server=SAWANT-PC\SQLEXPRESS;Database=PR;Trusted_Connection=True")


        sqlq = "create table " & EmpID.Text & "" + "(myId nvarchar(MAX), myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)"

        cmd = New SqlCommand(sqlq, con)



View Complete Post

More Related Resource Links

Incorrect syntax near 'GO' error while running a sql script ?


I am using Visual Studio 2008

I have one Database A

now i want to create Database B just like Database A

I generated a script of Database A

and created fresh Database B

Now, when i try to run the generated script against Database B, i get this error, why ? how to fix it ?

sql error

For your information:

I have checked in my script it is:


and i have also tried to save the sql script in notepad as: ANSI, UTF-8 and UNICODE

and then i copied from txt file to query but still doesn't work and getting the same error

and these are the option that i selected/used while creating my script:


Incorrect syntax near "("


Hi, below is a sub I wrote to run an SQLDataSource UpdateCommand. This is customized layer of a createUserWizard. I know I should probably have another table for the addt'l data and just FK the UserId...but I'd rather update the existing record and add the data to the existing row in the user (membership) table.

Can someone tell me what I'm doing wrong on this sub. The error is at the last line, "DataSource.Update()"


 Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
        FormsAuthentication.SetAuthCookie(CreateUserWizard1.UserName, False)

        Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName"), TextBox)
        Dim DataSource As SqlDataSource = DirectCast(CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)

        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        Dim UserGUID As Object = User.ProviderUserKey

        DataSource.UpdateParameters.Add("UserId", UserGUID.ToString())

End Sub



Incorrect syntax near '<'

It was suggested that I use xmldocument.load to do a sql insert statement instead of BULK INSERT.  However when I run the Sub I am getting this error:  "Incorrect syntax near '<'.   "Here is my code, I have no clue what is causing this error, or how to fix it. Sub AO() Dim Z As String = Microsoft.VisualBasic.Format(Today.AddDays(-1), "MMddyyyy") Dim AO_Name As New String("\\Net\Import\AO-M_" & (Z) & ".xml") Console.WriteLine(AO_Name) Dim AOSQL As String Dim conn As New SqlConnection("Server=DEB\DEVDB;Database=MTrans;User Id=******;Password=**************************;") Dim cmd As New SqlCommand Dim x as New XMLDocument x.Load(AO_Namme) Dim xx As String xx=x.OuterXml AOSQL = "DECLARE @xml XML" + Environment.NewLine() + _ "SELECT @xml = " + xx + _ "Insert into AO (ASSET_OWNER_NAME,SCHEDULED_DATE,SETTLEMENT_CODE, INVOICE, OPERATING_DATE, DA_ADMIN, DA_ASM_REG, DA_ASM_SPIN)" + Environment.NewLine() + _ "SELECT ASSET_OWNER_NAME,SCHEDULED_DATE,CAST(SETTLEMENT_CODE AS smallint) AS SETTLEMENT_CODE, INVOICE, OPERATING_DATE, DA_ADMIN, DA_ASM_REG, DA_ASM_SPIN" + Environment.NewLine() + _ "FROM " + Environment.NewLine() + _ "(SELECT " + Environment.NewLine() + _ "summary.x.value('NAME[1]', 'VARCHAR(10)') AS ASSET_OWNER_NAME,summary.x.value('SCHEDULED_DAT

Incorrect syntax near '>'.

Hello everyone,I am getting a strange error message; Incorrect syntax near '>'.I made a listview with some dropdownmenu and selectboxes to select from untill the query shows in the listview.Now the query goes well and shows the first page of 4 rows as I wanted it.The pager shows 5 pages and if I a want to click on the next page I get this message. Incorrect syntax near '>'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '>'. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SqlException (0x80131904): Incorrect syntax near '>'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584 System.Data.SqlC

EXEC 17P_Comose will give incorrect syntax error. Because of numeric name

I am working with a sql server database with about 50 stored procedures. The database and stored procedureswere not created by me. The stored procedures all begin with a number in their name. Example: 17P_Comsetter The problem I am having is that if I try and execute the stored procedure at the command line in Query Analyzer,the query analyzer appears not to like that the stored procedure begins with a number. For example: If I try an run the stored procedure as follows: EXEC 17P_Comsetter Then I get the following error message:Msg 102, ..... Incorrect Syntax near '17' If I rename the stored procedure so that it does not begin with a number, then I do not get the error. The problemis that the company I am working at has a policy in place that stored procs must begin with a number.I am using SQL server 2005. Does anyone know why I am getting this error message?

LINQ to SQL "Incorrect syntax near the keyword 'WHERE'"


I am having a problem that creeps up over and over when using LINQ to SQL.  I am getting the error: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'.

Now I have done a great deal of digging, and the only cause I can seem to find is when users are overriding the Equals() or GetHasCode() methods of the generated classes.  I am not overriding either.  I am getting this error on two different project with two different databases.  I have tried everything every post I have found suggests.  I have even scrapped my dbml file and re-created, all to no avail.

Anyone have any thoughts?  They would be greatly appreciated!

Ryan Sakry
Program Manager
Retail Information Technology Enterprises

Receiving error message: Incorrect syntax near 'au'.

"SELECT am.State,au.Email,am.Phone,au.UserId,au.Name FROM table1 au INNER JOIN table2 am on au.UserId = am.UserId" 

"UPDATE table1 au INNER JOIN table2 am on au.UserId = am.UserId SET am.State = @State,au.Email = @Email,am.Phone = @Phone,au.UserId = @UserId,au.Name = @Name"


Might someone be able to tell me what may be causing the above error message in one or both of the above statements?

Many thanks


Line 1: Incorrect syntax near ','. Unclosed quotation mark before the character ...


Can someone please review my code and see where I can be missing information. I get the following error:

Line 1: Incorrect syntax near ','. Unclosed quotation mark before the character string ' )'. at System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.RunExecuteNonQuer yTds(String methodName, Boolean async) at System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at _Default.SaveToDatabase(String SavePath) in C:\Inetpub\wwwroot\Webfile1\Default.aspx.vb:line 78

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Protected Sub Submit1_Click(ByVal sender

BCP statement syntax incorrect


Hi guys im getting this error with my code, 



1.The syntax of the command is incorrect.


declare @command varchar(1000)

set @command = 'BCP "SELECT DateOfBirth FROM Policy.ClientDetails" out "C:\Users\Public\Documents\Test Order\myfile.txt" -T -t|'

exec xp_cmdshell @command

Where am i getting it wrong?




Msg 102, Level 15, State 1, Line 12 INCORRECT SYNTAX NEAR ')'

CREATE Table Item(
ItemID    numeric(18,2)  PRIMARY KEY,
VendorID   numeric(18,0)  NOT NULL,
ItemDescription  Char(50)   NULL,
PurchaseDate  DateTime   NOT NULL,
ItemCost   numeric(18,2)  NOT NULL,
ItemPrice   numeric(18,2)  NOT NULL,
  REFERENCES Vendor(VendorID)
);      <<<<HERE IS THE ERROR

Incorrect syntax near 's'.


Server Error in '/New Folder (2)' Application.

Incorrect syntax near 's'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 's'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

Source Error:

Incorrect syntax near ','.


Hello, can someone please tell me what is causing the error message below? (apparently happening in the FormView.ItemUpdating Event - it had been working fine until I collapsed 2 columns into one new one called "DMA"). Thanks.     


 <td><asp:DropDownList ID="DMAddl" runat="server" autopostback="true" DataTextField="DMA" DataValueField="UserId"

            text='<%# Bind("DMA")%>'>

            <asp:listitem text="select" value=""/>

            <asp:listitem text="Abilene, TX" value="1001"/>

<asp:listitem text="Chicago, IL" value="1002"/>       


                <asp:requiredfieldvalidator ID="DMATextBoxRequired" runat="server" ControlToValidate="DMAddl" ErrorMessage="Please note that all fields are required" SetFocusOnError="true" display="static" CssCla

Incorrect syntax near the keyword 'where'


When I use the sqldatasource select paremeters like that:

<asp:SqlDataSource ID="dtsrcHotAreaLabor" runat="server"
        ConnectionString="<%$ ConnectionStrings:ContentMiningConnectionString %>"
        SelectCommand="SELECT * FROM [HotAreaLabors] ORDER BY [Date] where [UserAlias]=@UserAlias"
         UpdateCommand="UPDATE [HotAreaLabors] set [Date]=@Date,[LaborType]=@LaborType,[Comments]=@Comments where [lid]=@lid and [UserAlias]=@UserAlias"
        DeleteCommand="DELETE FROM [HotAreaLabors] WHERE [lid]=@lid and [UserAlias]=@UserAlias"
         <asp:Parameter  Type="String" Name="UserAlias"/>

msxml6.dll: The filename, directory name,or volume label syntax is incorrect


msxml6.dll: The filename, directory name,
 or volume label syntax is incorrect.

when i use the validation given in the script

'Validate the data file prior to bulkload
Dim sOutput

sOutput = ValidateFile("c:\test\SampleXMLData.xml", "", "c:\test\SampleSchema.xml")

WScript.Echo sOutput

'If FileValid Then
   ' Check constraints and initiate transaction (if needed)
   ' objBL.CheckConstraints = True
   ' objBL.Transaction=True
  'Execute XML bulkload using file.

  objBL.Execute "c:\test\SampleSchema.xml", "c:\test\SampleXMLData.xml"
  set objBL=Nothing
'End If


Function ValidateFile(strXmlFile,strUrn,strXsdFile)
   ' Create a schema cache and add SampleSchema.xml to it.
   Dim xs, fso, sAppPath
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set xs = CreateObject("MSXML2.XMLSchemaCache.6.0")
   sAppPath = fso.GetFolder(".")
   xs.Add strUrn, sAppPath & "\" & strXsdFile

   ' Create an XML DOMDocument object.
   Dim xd
   Set xd = CreateObject(&quo

Incorrect syntax near '%'. When trying to create/alter system stored procedure


Sql Server 2005 SP3

After finally figuring out that for whatever reason the sp [sys].[sp_refreshsqlmodule] was not loaded I found the procedure on another machine and tried to create it on the machine missing the sp. I get an error: Incorrect syntax near '%'. The error applies to 2 lines in the sp:


EXEC %%Object(MultiName = @name).LockMatchID

Another ERROR Message Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'COLUMN'


Ok, I would like to ask you this if I may,

On another database I created a table named FICTION

and the table looks like this:


Now I am trying to change the data type in TITLE to CHAR(50)







Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'MODIFY'





Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'MODIFY'.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend