By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,316 Members | 2,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,316 IT Pros & Developers. It's quick & easy.

Stored procedure

P: n/a
I am trying to code an compile a stored procedure without success. So I
generated one using Microsoft Visule C# .Net. and it follows. One of the
problems is that it will not compile. Some of the message won't to put ';'
all over the place, I some need help!!! These are some of the compile
messages.

; expected
Cannot use more than one type in a for, using, fixed, or declaration
statement
= (cannot specify constructor arguments in declaration)
Identifier expected
Invalid expression term ')'
Invalid expression term ','

static void SubmitChangesViaDataAdapter()
{
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandDetail' AND
user_name(uid) = 'dbo')
DROP PROCEDURE [dbo].[InsertCommandDetail];
GO

CREATE PROCEDURE [dbo].[InsertCommandDetail]
{
@Param1 int,
@Param2 char(30),
@Param3 money,
@Param4 money,
@Param5 money,
@filler char(50)
}
AS
SET NOCOUNT OFF;
INSERT INTO services([service-code], [service-description],
[large-animal-cost], [medium-animal-cost], [small-animal-cost]) VALUES
(@Param1, @Param2, @Param3, @Param4, @Param5, @filler);
SELECT [service-code], [service-description], [large-animal-cost],
[medium-animal-cost], [small-animal-cost], [service-nbr] FROM services WHERE
([service-nbr] = @@IDENTITY) ORDER BY [service-code];
GO

}

--
Norm Bohana
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello nbohana,

Stored procedures do not live in C# code. They live in SQL Server
databases. You need to use the SQL Enterprise Manager tool to find your
database and open it. From there, assuming you have permission, you can add
the stored procedure.

Then, your C# code is free to call it.

It is called a stored procedure because it is a procedure that is stored in
the database.

Also note:
INSERT INTO services([service-code], [service-description],
[large-animal-cost], [medium-animal-cost], [small-animal-cost]) VALUES
(@Param1, @Param2, @Param3, @Param4, @Param5, @filler);
This is not a valid SQL statement. Your Insert Into statement has to have
the same number of fields in the first half as values in the second. You
have five fields in the first half, and six values in the second. I don't
know what "filler" means to you, but to me, it sounds like something we used
to use in ISAM databases (yes... my hair is grey in spots :-). Filler
fields are not used in SQL Server except in rare situations. My guess is
that you are applying information from another DB to the SQL Server system.

Also note: SELECT [service-code], [service-description], [large-animal-cost],
[medium-animal-cost], [small-animal-cost], [service-nbr] FROM services
WHERE
([service-nbr] = @@IDENTITY) ORDER BY [service-code];
The Order By clause is unnecessary. The Select statement above will only
select a single record, ever.

Also, using Identity columns is not always scalable. (In other words, it
becomes a hassle if you need to have multiple databases that share records).
May I suggest that you could use a 'uniqueidentifier' column, and that your
C# app would create the value (Guid.NewGuid()) and pass it with the new
record, rather than having the database create it? It's a good habit to
have.

Hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"nbohana" <nb*****@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...I am trying to code an compile a stored procedure without success. So I
generated one using Microsoft Visule C# .Net. and it follows. One of the
problems is that it will not compile. Some of the message won't to put ';'
all over the place, I some need help!!! These are some of the compile
messages.

; expected
Cannot use more than one type in a for, using, fixed, or declaration
statement
= (cannot specify constructor arguments in declaration)
Identifier expected
Invalid expression term ')'
Invalid expression term ','

static void SubmitChangesViaDataAdapter()
{
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandDetail' AND
user_name(uid) = 'dbo')
DROP PROCEDURE [dbo].[InsertCommandDetail];
GO

CREATE PROCEDURE [dbo].[InsertCommandDetail]
{
@Param1 int,
@Param2 char(30),
@Param3 money,
@Param4 money,
@Param5 money,
@filler char(50)
}
AS
SET NOCOUNT OFF;
INSERT INTO services([service-code], [service-description],
[large-animal-cost], [medium-animal-cost], [small-animal-cost]) VALUES
(@Param1, @Param2, @Param3, @Param4, @Param5, @filler);
SELECT [service-code], [service-description], [large-animal-cost],
[medium-animal-cost], [small-animal-cost], [service-nbr] FROM services
WHERE
([service-nbr] = @@IDENTITY) ORDER BY [service-code];
GO

}

--
Norm Bohana

Nov 17 '05 #2

P: n/a
Thanks Nick, I actually did create them in the sql server, I just didn't how
to use them.
"Nick Malik [Microsoft]" wrote:
Hello nbohana,

Stored procedures do not live in C# code. They live in SQL Server
databases. You need to use the SQL Enterprise Manager tool to find your
database and open it. From there, assuming you have permission, you can add
the stored procedure.

Then, your C# code is free to call it.

It is called a stored procedure because it is a procedure that is stored in
the database.

Also note:
INSERT INTO services([service-code], [service-description],
[large-animal-cost], [medium-animal-cost], [small-animal-cost]) VALUES
(@Param1, @Param2, @Param3, @Param4, @Param5, @filler);


This is not a valid SQL statement. Your Insert Into statement has to have
the same number of fields in the first half as values in the second. You
have five fields in the first half, and six values in the second. I don't
know what "filler" means to you, but to me, it sounds like something we used
to use in ISAM databases (yes... my hair is grey in spots :-). Filler
fields are not used in SQL Server except in rare situations. My guess is
that you are applying information from another DB to the SQL Server system.

Also note:
SELECT [service-code], [service-description], [large-animal-cost],
[medium-animal-cost], [small-animal-cost], [service-nbr] FROM services
WHERE
([service-nbr] = @@IDENTITY) ORDER BY [service-code];


The Order By clause is unnecessary. The Select statement above will only
select a single record, ever.

Also, using Identity columns is not always scalable. (In other words, it
becomes a hassle if you need to have multiple databases that share records).
May I suggest that you could use a 'uniqueidentifier' column, and that your
C# app would create the value (Guid.NewGuid()) and pass it with the new
record, rather than having the database create it? It's a good habit to
have.

Hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"nbohana" <nb*****@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
I am trying to code an compile a stored procedure without success. So I
generated one using Microsoft Visule C# .Net. and it follows. One of the
problems is that it will not compile. Some of the message won't to put ';'
all over the place, I some need help!!! These are some of the compile
messages.

; expected
Cannot use more than one type in a for, using, fixed, or declaration
statement
= (cannot specify constructor arguments in declaration)
Identifier expected
Invalid expression term ')'
Invalid expression term ','

static void SubmitChangesViaDataAdapter()
{
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandDetail' AND
user_name(uid) = 'dbo')
DROP PROCEDURE [dbo].[InsertCommandDetail];
GO

CREATE PROCEDURE [dbo].[InsertCommandDetail]
{
@Param1 int,
@Param2 char(30),
@Param3 money,
@Param4 money,
@Param5 money,
@filler char(50)
}
AS
SET NOCOUNT OFF;
INSERT INTO services([service-code], [service-description],
[large-animal-cost], [medium-animal-cost], [small-animal-cost]) VALUES
(@Param1, @Param2, @Param3, @Param4, @Param5, @filler);
SELECT [service-code], [service-description], [large-animal-cost],
[medium-animal-cost], [small-animal-cost], [service-nbr] FROM services
WHERE
([service-nbr] = @@IDENTITY) ORDER BY [service-code];
GO

}

--
Norm Bohana


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.