473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with stored procedure

Hi Folks,

I've created a stored procedure (Incident_Add) and called it, but when I
excecute it in the code it says: "System.Data.SqlClient.SqlException: Line
1: incorrect syntax at Incident_Add."

When I run the procedure from VisualStudio ServerExplorer it works, but not
in this way,

Any Suggestions?

Stored Procedure:
ALTER PROCEDURE dbo.Incident_Add

@IncidentName NVarChar(50),

@IncidentPriority Int,

@RegisteredBy Int,

@ClientId Int,

@AffectedUser Int,

@AffectedAsset int,

@Severity Int,

@Category1 Int,

@Category2 Int,

@Category3 Int,

@Category4 Int,

@Category5 Int,

@Category1Other NVarChar(30),

@Category2Other NVarChar(30),

@Category3Other NVarChar(30),

@Category4Other NVarChar(30),

@Category5Other NVarChar(30)
AS

INSERT Incident

(

IncidentName,

IncidentPriority,

RegisteredBy,

ClientId,

AffectedUser,

AffectedAsset,

Severity,

Category1,

Category2,

Category3,

Category4,

Category5,

Category1Other,

Category2Other,

Category3Other,

Category4Other,

Category5Other

)

VALUES

(

@IncidentName,

@IncidentPriority,

@RegisteredBy,

@ClientId,

@AffectedUser,

@AffectedAsset,

@Severity,

@Category1,

@Category2,

@Category3,

@Category4,

@Category5,

@Category1Other,

@Category2Other,

@Category3Other,

@Category4Other,

@Category5Other

)

RETURN @@IDENTITY

Code:

SqlCommand scSaveIncident = new SqlCommand("Incident_Add",this.oSql);

scSaveIncident.Parameters.Add(new
SqlParameter("@IncidentName",OleDbType.VarChar)).V alue =
this.textBoxSubject.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@IncidentPriority",OleDbType.Integer )).Value =
Convert.ToInt32(this.dropPriority.SelectedItem.Tex t);

scSaveIncident.Parameters.Add(new
SqlParameter("@RegisteredBy",OleDbType.Integer)).V alue =
this.dropUser.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@ClientId",OleDbType.Integer)).Value =
this.dropClient.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@AffectedUser",OleDbType.Integer)).V alue =
this.dropClientUser.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@AffectedAsset",OleDbType.Integer)). Value =
this.dropAsset.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Severity",OleDbType.Integer)).Value =
Convert.ToInt32(this.dropSeverity.SelectedItem.Tex t);

scSaveIncident.Parameters.Add(new
SqlParameter("@Category1",OleDbType.Integer)).Valu e =
this.dropCategory1.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category2",OleDbType.Integer)).Valu e =
this.dropCategory2.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category3",OleDbType.Integer)).Valu e =
this.dropCategory3.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category4",OleDbType.Integer)).Valu e =
this.dropCategory4.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category5",OleDbType.Integer)).Valu e =
this.dropCategory5.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category1Other",OleDbType.VarChar)) .Value =
this.CategoryOther1.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category2Other",OleDbType.VarChar)) .Value =
this.CategoryOther2.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category3Other",OleDbType.VarChar)) .Value =
this.CategoryOther3.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category4Other",OleDbType.VarChar)) .Value =
this.CategoryOther4.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category5Other",OleDbType.VarChar)) .Value =
this.CategoryOther5.Text;

//scSaveIncident.Parameters.Add(new
SqlParameter("@Description",OleDbType.LongVarChar) ).Value =
this.dropClient.SelectedValue;
scSaveIncident.ExecuteQuery();



Nov 16 '05 #1
2 2072
Hi,

I believe you are missing the ( ) around the arguments, this is what VS.NET
gives you when you select "New SP"
CREATE PROCEDURE dbo.StoredProcedure1

/*

(

@parameter1 datatype = default value,

@parameter2 datatype OUTPUT

)

*/

AS

/* SET NOCOUNT ON */

RETURN
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Gaab" <sp**@adiso.nl> wrote in message
news:10*************@corp.supernews.com...
Hi Folks,

I've created a stored procedure (Incident_Add) and called it, but when I
excecute it in the code it says: "System.Data.SqlClient.SqlException: Line
1: incorrect syntax at Incident_Add."

When I run the procedure from VisualStudio ServerExplorer it works, but not in this way,

Any Suggestions?

Stored Procedure:
ALTER PROCEDURE dbo.Incident_Add

@IncidentName NVarChar(50),

@IncidentPriority Int,

@RegisteredBy Int,

@ClientId Int,

@AffectedUser Int,

@AffectedAsset int,

@Severity Int,

@Category1 Int,

@Category2 Int,

@Category3 Int,

@Category4 Int,

@Category5 Int,

@Category1Other NVarChar(30),

@Category2Other NVarChar(30),

@Category3Other NVarChar(30),

@Category4Other NVarChar(30),

@Category5Other NVarChar(30)
AS

INSERT Incident

(

IncidentName,

IncidentPriority,

RegisteredBy,

ClientId,

AffectedUser,

AffectedAsset,

Severity,

Category1,

Category2,

Category3,

Category4,

Category5,

Category1Other,

Category2Other,

Category3Other,

Category4Other,

Category5Other

)

VALUES

(

@IncidentName,

@IncidentPriority,

@RegisteredBy,

@ClientId,

@AffectedUser,

@AffectedAsset,

@Severity,

@Category1,

@Category2,

@Category3,

@Category4,

@Category5,

@Category1Other,

@Category2Other,

@Category3Other,

@Category4Other,

@Category5Other

)

RETURN @@IDENTITY

Code:

SqlCommand scSaveIncident = new SqlCommand("Incident_Add",this.oSql);

scSaveIncident.Parameters.Add(new
SqlParameter("@IncidentName",OleDbType.VarChar)).V alue =
this.textBoxSubject.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@IncidentPriority",OleDbType.Integer )).Value =
Convert.ToInt32(this.dropPriority.SelectedItem.Tex t);

scSaveIncident.Parameters.Add(new
SqlParameter("@RegisteredBy",OleDbType.Integer)).V alue =
this.dropUser.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@ClientId",OleDbType.Integer)).Value =
this.dropClient.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@AffectedUser",OleDbType.Integer)).V alue =
this.dropClientUser.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@AffectedAsset",OleDbType.Integer)). Value =
this.dropAsset.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Severity",OleDbType.Integer)).Value =
Convert.ToInt32(this.dropSeverity.SelectedItem.Tex t);

scSaveIncident.Parameters.Add(new
SqlParameter("@Category1",OleDbType.Integer)).Valu e =
this.dropCategory1.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category2",OleDbType.Integer)).Valu e =
this.dropCategory2.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category3",OleDbType.Integer)).Valu e =
this.dropCategory3.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category4",OleDbType.Integer)).Valu e =
this.dropCategory4.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category5",OleDbType.Integer)).Valu e =
this.dropCategory5.SelectedValue;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category1Other",OleDbType.VarChar)) .Value =
this.CategoryOther1.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category2Other",OleDbType.VarChar)) .Value =
this.CategoryOther2.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category3Other",OleDbType.VarChar)) .Value =
this.CategoryOther3.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category4Other",OleDbType.VarChar)) .Value =
this.CategoryOther4.Text;

scSaveIncident.Parameters.Add(new
SqlParameter("@Category5Other",OleDbType.VarChar)) .Value =
this.CategoryOther5.Text;

//scSaveIncident.Parameters.Add(new
SqlParameter("@Description",OleDbType.LongVarChar) ).Value =
this.dropClient.SelectedValue;
scSaveIncident.ExecuteQuery();


Nov 16 '05 #2
>Code:
SqlCommand scSaveIncident = new SqlCommand("Incident_Add",this.oSql);


You have to tell it that it's a STORED PROC !

scSaveIncident.CommandType = CommandType.StoredProcedure;

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 16 '05 #3

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

Similar topics

2
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
2
by: Rhino | last post by:
I am getting an sqlcode of -927 when I execute SQL within a COBOL stored procedure in DB2 OS/390 Version 6 on OS/390. I have looked at the error message for that condition and tried everything I...
5
by: Timppa | last post by:
Hi, Could anyone help me with my problem ? Environment: Access 2000 and Sql Server 2000. I have a stored procedure as follows: DROP table1 SELECT alias1.field1,alias2.field2,table2.field6...
6
by: Not4u | last post by:
Hello Config : SQL 2000 on WIN 2000 (IIS 5.0) In my ASP page for some queries i have this error : Microsoft OLE DB Provider for SQL Server error '80040e31' Timeout expired
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
4
by: nishi57 | last post by:
I hope I can get some help regarding this issue, which has been going on for a while. I have a desktop user who is having problem running "Stored Procedures". The DB2 Connect application works fine...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
1
by: amgupta8 | last post by:
Note: This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2. Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.