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 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
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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";
|
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)
|
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()
|
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.
| |
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.
|
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
|
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.
|
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
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |