.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

Syntax error for CURSOR using ADO.NET

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :Sql Server
 have some code that uses ADO.NET like:
    // Get rid of the out of band data (non-ascii stuff)
    command.CommandText = "DECLARE @MyCursor FOR SELECT [AmazonCategory],[BuyCategory] FROM [#DefinitionTable] " +
          "DECLARE @AmazonCategory nvarchar(128), @BuyCategory nvarchar(128) " +
          "OPEN @MyCursor " +
          "FETCH NEXT FROM @MyCursor INTO @AmazonCategory, @BuyCategory " +
          "WHILE @@FETCH_STATUS = 0 " +
          "BEGIN " +
          " UPDATE [#DefinitionTable] " +
          " SET AmazonCategory = @AmazonCategory, BuyCategory = @BuyCategory " +
          " WHERE CURRENT OF @MyCursor " +
          " FETCH NEXT FROM @MyCursor INTO @AmazonCategory, @BuyCategory " +
          "END " +

View Complete Post

More Related Resource Links

Syntax error (missing operator) in query expression

Good Day Gurus!

I have a Excel user application which has a user form (named 'Registo') that displays criteria and an image that has been entered in it's corresponding spreadsheet. This works the way it should.  There's also the ability to search the spreadsheet via a form (by clicking 'Pesquisar' button) this opens a search form. However, I having a bit of a problem with it. When I try to search for something it basically doesn't do anything at all. It just sits there. So I tried to debug it and I think I'm having a problem with either the JET db engine or somethign with teh query or maybe I don't have the correct reference.

I 'borrowed' this Excel application from another forum because it's exactly what I'm looking for! However, I suck at vb.

So I was hoping somebody could take a look at the code and see if I'm missing something?  I'm kinda' desparate to get this working because I'm been trying to figure it out for days and I'm running out of time.  Cry
Option Explicit

'constantes para auxiliar na verificação do código
Private Const Ascendente As Byte = 0

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:


syntax error in calling mailhelper class??


I use to program with VB.NEt. I am just learning C#.  I need to learn C# b/c I am a SharePoint developer and Admin and thats what SharePoint is coded from.


so I am trying to create a simple form that sends an email but am getting an error with calling this function:

       mailHelper.SendMailMessage("admin@pointeightpower.com", "jstevens@pointeightpower.com", null, null, "August Heat Stress", String.Concat(txtSupervisorName.Text.Trim, "reviewed this month's training on ", System.DateTime.Now));


it says param string has some invalid arguements. I dont know why. it works in VB.Net. any help? Thanks

Strange Problem - SSIS Fails with "Syntax error, permission violation, or other nonspecific error".

Hello, I have a strange issue while I am deploying a package to one of the environment server. I have 2 XML Source, in the DataFlow, and one will extracted based on a value of variable that is passed from run time (package is executed from a Job) and other will be extracted all time. The next Step I have is a Execute SQL Task in ControlFlow wihich will execute after DataFlow. This has 2 input parameters and some SQL query that uses the param. Now this one fail on the target environment with below error: failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. I got the error when I did a SSIS Text File Log. Note: If I run the package in BIDS with the same XML files it work. Also when I deploy the package to my Dev Server it works. When I compare the Dev DB with the target environment DB - Both are same. The Service Acount has permission - as I can see the DataFlow task completed. Another Point: The XML Load Data Flow that executes based on the Variable Value does not execute on target environment, even if the value is passed as "True" (It is Boolean Type) But this variable is NOT an input for the Execute SQL task that fails. I am not sure w

A MOF syntax error occurred - SQL Server ENT 2008 R2 on Windows Server 2008 R2

Having trouble getting SQL Server 2008 R2 installed on a Windows Server 2008 R2. Getting an MOF syntax error at this point durring the installation "SqlEngineConfigAction_install_confignonrc_Cpu64". Below is the section of the Details.txt file that includes the error. Any help on this would be greatly appreciated.   2010-07-28 10:51:35 Slp: Running: C:\Windows\system32\WBEM\mofcomp.exe "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\xesospkg.mof" 2010-07-28 10:51:35 Slp: Microsoft (R) MOF Compiler Version 6.1.7600.16385 2010-07-28 10:51:35 Slp: Copyright (c) Microsoft Corp. 1997-2006. All rights reserved. 2010-07-28 10:51:35 Slp: Parsing MOF file: C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\xesospkg.mof 2010-07-28 10:51:35 Slp: MOF file has been successfully parsed 2010-07-28 10:51:35 Slp: Storing data in the repository... 2010-07-28 10:51:36 Slp: An error occurred while processing item 17 defined on lines 201 - 222 in file C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\xesospkg.mof: 2010-07-28 10:51:36 Slp: Compiler returned error 0x800706beError Number: 0x800706be, Facility: Win32 2010-07-28 10:51:36 Slp: Description: The remote procedure call failed. 2010-07-28 10:51:36 Slp: 2010-07-28 10:51:36 Slp: Sco: Compile operation for mof file C:\Program Files\Microsoft SQL S

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?

invalid syntax near '/' error


First time using parameters, not having much luck.

Keep getting 'invalide syntax near '/' when trying this code.

Any idea what might be the issue?:

string strConnString = ConfigurationManager.ConnectionStrings["WebConfigConnectionString"].ConnectionString;
            SqlConnection sqlConn = new SqlConnection(strConnString);
            SqlCommand sqlComm = new SqlCommand();
            sqlComm = sqlConn.CreateCommand();
            sqlComm.CommandText = @"DELETE FROM Assets WHERE Image = @/Images/mypic1.jpg";
            sqlComm.Parameters.Add("@/Images/mypic1.jpg", SqlDbType.NVarChar);
            sqlComm.Parameters["@/Images/mypic1.jpg"].Value = "Image";

Insert statement giving me syntax error


Good evening,


I have a MS Access table with the "ModelID" column set as AutoNumber and primary key. The ModelID is set as Field Size --> Long Integer, New Values --> Increment, Format --> General Number, Indexed --> Yes (No Duplicates).

Here is the code i am trying to execute, and is giving me an exception -> insert into syntax error:

string strInsert = "INSERT INTO tbl_Models (fName, lName, Image, Answer1, Answer2, Answer3, Answer4, Answer5, Votes, ImageHead, Age, Program, StudentID, PhoneNumber, EMail) VALUES (@fName, @lName, @Image, @Answer1, @Answer2, @Answer3, @Answer4, @Answer5, @Votes, @ImageHead, @Age, @Program, @StudentID, @PhoneNumber, @EMail)";
        OleDbCommand cmdInsert = new OleDbCommand(strInsert, myCon);

        cmdInsert.Parameters.AddWithValue("@fName", txtFirstName.Text.ToString());
        cmdInsert.Parameters.AddWithValue("@lName", txtLastName.Text.ToString());
        cmdInsert.Parameters.AddWithValue("@Image", FileUploadBody.FileName.ToString() + sRandomBody);
        cmdInsert.Parameters.AddWithValue("@Answer1", txtWhyBeAModel.Text.ToString());
        cmdInsert.Parameters.AddWithValue("@Answer2", "");
        cmdInsert.Parameters.AddWithValue("@Answer3", "

Error: Invalid dn syntax specified



I tried to use Authentication form with LDAP but when I run
my web application I received error: Invalid dn syntax specified. This is my code:

public bool IsAuthenticated(string domain, string username, string password)
// string domainAndUsername = domain + @"\" + username;
string domainAndUsername = "http://localhost:389\rjsmith";
// DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, password);// _path = LDAP://localhost:389/dc=example,dc=com
DirectoryEntry entry = new DirectoryEntry("LDAP://localhost:389",domainAndUsername,"rJsmitH");
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";

SearchResult result = search.FindOne();

if(null == result)
return false;
_path = result.Path;
_filterAttribute = (String)result.Properties[&quo

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


SSIS 2008-Variable Expression Type Cast Syntax Error


Hi all members.

I need to ask for the following code. I need to convert the variable into a string.

"Select Distinct convert (int ,A.CustomerCategory) as AccountReceivableCategoryID, convert (varchar(40), B.Text) as AccountReceivableCategoryNameE
from Inkunde A , inpara B
where A.CustomerCategory= B.SearchItem
and B.Language1 = 'EN'
and B.ParameterName = 'CATEGORY'
and A.CustomerCategory = (DT_STR,200,1252) "+  @[User::CategoryID] +"
Order By A.CustomerCategory"

Kindly any member let me know, How to correctly use the Type Cast fucntion in variables

Thanks and Best Regards,


SQL Query within a form fails with "parser error" - syntax not correct?


Hello, I've created an Expression Web form with a SQL datasource which is doing a query/select statement.

Somehow it appears that I'm making a syntax error. When I divide the query in two and execute them separate, it works fine.

I need to filter for an EventType, Region and Today's date + a custom interval (like 7 day's for a week)

The parameters come from a search form where the user can select these values via a dropdown list.

The two separate (and working) queries within my form are:


Query nr.1 :

"Select * from Events WHERE  (([EventType] LIKE '%' + @EventType + '%') AND ([Region] LIKE '%' + @Region + '%'))">


<asp:formparameter DefaultValue="%" FormField="EventType" />

<asp:formparameter DefaultValue="%" FormField="Region" />


Query nr.2 :






Error when creating Issues Web Database: The formula contains a syntax error or is not supported.



I have been trying to create an Issues Web Database on one of our MOSS 2010 servers, but I keep getting the error "The formula contains a syntax error or is not supported" when I try to. I have tried this on one of our other 2010 environments and it works fine but for some reason it happens just one this one.

In the error logs I found this:

Error updating field: List: Issues, SchemaXml: <Field DisplayName="OpenedDate" Type="DateTime" Required="TRUE" Format="DateOnly" xmlns="http://schemas.microsoft.com/sharepoint/soap/" Name="OpenedDate"><DefaultFormula>=TODAY()</DefaultFormula><DefaultFormulaValue></DefaultFormulaValue><Validation Message="Value must be greater than 1/1/1900.">=OpenedDate&gt;=DATETIME(1900,1,1,0,0,0)</Validation></Field>. Exception: Microsoft.SharePoint.SPException: The formula contains a syntax error or is not supported.

Does anyone have an idea as to what the cause might be?


Syntax error adding a parameter to xp_cmdshell command



I am trying to add a parameter to a bcp query that will be run in xp_cmdshell but am getting a syntax error at the '+' character.  Been staring at it for two hours and have concluded that  some outside help is needed. 

The command is:

EXEC xp_cmdshell 'bcp "SELECT * FROM [CensusData].[dbo].[Main] where zBarCode = ' + @zBarCode + '"  queryout "C:\temp_housing_data.txt" -T -c -t -S "MyServerName"'

The syntax is on the first '+' character and it simply says "Incorrect syntax near '+'"

Please help.

Database Tuning Advisor, Stored Procedure with datetime parameters, syntax error


I receive these error(s) in the Tuning Log. I have several stored procedures and they all use a datetime parameter.

E000    exec <some sproc name> ''2009-01-01 00:00:00:000'',''2010-09-30 00:00:00:000'',N'',N'',NULL,NULL,NULL,NULL,NULL,NULL         1    [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near '2009'.

I am using SQL 2005. Any suggestions?

Thanks, Reece

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)







exec syntax error?


hey guys, does anyone know why am i getting error at the last line of this statement?:

create trigger StaffUpdateTrigger on Staff after update as

declare @datetime datetime set @datetime=getutcdate()

declare @q nvarchar(max)set @q='insert StaffUpdate('

declare @q2 nvarchar(max)set @q2=')select '

if update(PId)begin 

set @q=@q+'PId,'

set @q2=@q2+(select PId from inserted)


set @q = substring(@q, 1, len(@q)-1)

set @q2 = substring(@q2, 1, len(@q2-1)+' from inserted'


i tried this and it works:

declare @q nvarchar(max)set @q='select*from staff'

declare @q2 nvarchar(max)set @q2=''



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