473,657 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Line 1: Incorrect syntax near 'sp_Collect'.

Hi,

What is wrong with this code ? I got this error:

" Line 1: Incorrect syntax near 'sp_Collect'. "

which appears at the last line when | call the cm.ExecuteScala r . The sp
takes an int ID and returns a string Data. Using the debugger, I see that the
value of ID is correct.
Is this a C# problem, or SQL Server 7 problem ?

public string GetID(int ID)
{
SqlCommand cm = new SqlCommand("sp_ Collect'", sqlCon);
cm.Parameters.A dd(new SqlParameter("@ ID", ID));
return (string) cm.ExecuteScala r();
}

Thanks
Andrew
Feb 13 '08 #1
5 4492
Andrew wrote:
Hi,

What is wrong with this code ? I got this error:

" Line 1: Incorrect syntax near 'sp_Collect'. "

which appears at the last line when | call the cm.ExecuteScala r . The sp
takes an int ID and returns a string Data. Using the debugger, I see that the
value of ID is correct.
Is this a C# problem, or SQL Server 7 problem ?

public string GetID(int ID)
{
SqlCommand cm = new SqlCommand("sp_ Collect'", sqlCon);
cm.Parameters.A dd(new SqlParameter("@ ID", ID));
return (string) cm.ExecuteScala r();
}

Thanks
Andrew
Wrap it in a try catch and output the message
Feb 13 '08 #2
Try adding:
cm.CommandType = CommandType.Sto redProcedure;
(befoer the ExecuteScalar() )

You might also need to check whether your proc *selects* the value or
*prints* the value; ExecuteScalar() will only work for a SELECT - but
if this was the problem I would expect a different error message.

Marc
Feb 13 '08 #3
Not sure if this is the problem but if you copied and paste the code from
your project to the post, it looks like you have an extra apostrophe
character at the end of sp_Collect.

"Andrew" <An****@discuss ions.microsoft. comwrote in message
news:7C******** *************** ***********@mic rosoft.com...
Hi,

What is wrong with this code ? I got this error:

" Line 1: Incorrect syntax near 'sp_Collect'. "

which appears at the last line when | call the cm.ExecuteScala r . The sp
takes an int ID and returns a string Data. Using the debugger, I see that
the
value of ID is correct.
Is this a C# problem, or SQL Server 7 problem ?

public string GetID(int ID)
{
SqlCommand cm = new SqlCommand("sp_ Collect'", sqlCon);
cm.Parameters.A dd(new SqlParameter("@ ID", ID));
return (string) cm.ExecuteScala r();
}

Thanks
Andrew

Feb 13 '08 #4
The line:
cm.CommandType = CommandType.Sto redProcedure;

did the trick.
Thanks

"Marc Gravell" wrote:
Try adding:
cm.CommandType = CommandType.Sto redProcedure;
(befoer the ExecuteScalar() )

You might also need to check whether your proc *selects* the value or
*prints* the value; ExecuteScalar() will only work for a SELECT - but
if this was the problem I would expect a different error message.

Marc
Feb 13 '08 #5
First of all, you really haven't showed how the stored procedure is defined.
Are you using a RETURN statement to return the string in the stored
procedure? Or are you using a SELECT statement to return the string as a
record?

Stored procedures only return INT values. If you need a string returned you
can use a parameter in the stored procedure with the OUTPUT tag. Short
example below:

CREATE PROCEDURE sp_Collect
@ID INT,
@ReturnValue VARCHAR(255) OUTPUT
AS
SELECT @ReturnValue = stringfield FROM sometable WHERE idfield = @ID
GO

C# code:
public string GetID(int ID)
{
SqlCommand cm = new SqlCommand("sp_ Collect", sqlCon);
cm.Parameters.A dd(new SqlParameter("@ ID", ID));
SqlParameter paramReturnValu e = cm.Parameters.A dd("@ReturnValu e",
SqlDbType.VarCh ar, 14);
paramReturnValu e.Direction = ParameterDirect ion.Output;
cm.ExecuteNonQu ery();
return (string) paramReturnValu e;
}


"Andrew" <An****@discuss ions.microsoft. comwrote in message
news:7C******** *************** ***********@mic rosoft.com...
Hi,

What is wrong with this code ? I got this error:

" Line 1: Incorrect syntax near 'sp_Collect'. "

which appears at the last line when | call the cm.ExecuteScala r . The sp
takes an int ID and returns a string Data. Using the debugger, I see that
the
value of ID is correct.
Is this a C# problem, or SQL Server 7 problem ?

public string GetID(int ID)
{
SqlCommand cm = new SqlCommand("sp_ Collect'", sqlCon);
cm.Parameters.A dd(new SqlParameter("@ ID", ID));
return (string) cm.ExecuteScala r();
}

Thanks
Andrew

Feb 15 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1617
by: samuel | last post by:
Hi I wrote a macro in MS Access 2000. This is a .adp link on SQL server tables. I have 2 forms: script_selection & Form3 Form3 include 2 important fields: CD & line I want to write a macro who will be run when I click on a field (line) in
2
4356
by: Roger R. Smith | last post by:
I see this error in my ASP .NET code: I am trying to execute the following: private const string SQL_SELECT_USER = "SELECT User.Email, User.FirstName, User.LastName, User.Status, User.Phone, User.Privs FROM User INNER JOIN Login ON User.UserId = Login.UserId WHERE Login.UserId = @UserId AND Login.Password = @Password";
1
3404
by: bdastani | last post by:
I am trying to initialize a dataReader in C#, but I keep on gettin an exception error stating the following: System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) System.Data.SqlClient.SqlCommand.ExecuteReader() Labor.Labor.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\labor\labor.aspx.cs:72 System.Web.UI.Control.OnLoad(EventArgs e)
3
6044
by: Patrick.O.Ige | last post by:
Hi guys, I'm getting error:- System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '='. What could cause this ERRORR My code below:- Dim connString As String = "server=(local);database=Northwind;integrated security=true;" Dim objConnection As SqlConnection objConnection = New SqlConnection(connString) objConnection.Open()
1
11237
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." Explaining you the scene is the following Stored Proc.
6
2979
by: martin1 | last post by:
I just use DataSet to bind DataSetGrid and display from SQL DB. when starting run in Visual Studio 2005, get "Line 1: Incorrect syntax near '1'" error message from below fill line, objDataAdapter.Fill(objDataSet, "mindata") any help is greatly appriciated.
1
2343
by: iporter | last post by:
In the following code, the two Response.Write statements output exactly the same - I can copy and paste both into Query Analyzer, and run them fine. However, if I comment out line 3, the assignment of "SELECT T..." to the variable query, the last line produces the error: Line 1: Incorrect syntax near '<'. Many thanks in advance for any explanation - the problem is tearing my hair out!! Iain
1
31191
by: Ruth413 | last post by:
Hello - I am getting the these errors in my sql 2005 generated script. I am stuck with first error. Please help.... Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '('. Msg 319, Level 15, State 1, Line 11 Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
0
8304
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new records there is an error "Incorrect syntax near '-'. Must declare the scalar variable "@UserName". I worked out in design view,code is automatically generated.Iam not able fix the error. Iam working with Visual Web Developer-2005 Express Edition
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.