Re: Stored procedure



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" <nbohana@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DEF88E77-088E-48DD-B719-790A40F61038@xxxxxxxxxxxxxxxx
>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


.



Relevant Pages

  • Re: Stored procedure
    ... Thanks Nick, I actually did create them in the sql server, I just didn't how ... > the stored procedure. ... > to use in ISAM databases (yes... ... >> @Param3 money, ...
    (microsoft.public.dotnet.languages.csharp)
  • How to query two SQL Server instances
    ... I need to run a stored procedure, or make it simpler, to run a query to ... access the databases from two machines location at different locations. ... On client's machine A, say in city A, have installed SQL Server, another ... the databases in head office? ...
    (microsoft.public.sqlserver.programming)
  • Re: Same transaction on 2 different DB
    ... databases. ... Pro SQL Server 2000 Database Design - ... > tran, select insert and update some table from both the DB, this ... > has effects on both DB or only in the DB in which the stored procedure is? ...
    (microsoft.public.sqlserver.programming)
  • Re: How to get list of EventClasses in MSSQLServer2000
    ... statement inside a stored procedure has completed.') ... SQL Server statement or stored procedure.') ... Plan','Displays the plan tree of the Transact-SQL statement executed.') ... Login','Occurs when a SQL Server login is added or removed; ...
    (microsoft.public.sqlserver.security)
  • Re: why>?
    ... On your desktop-- you'll be running SQL Server behind the scenes. ... it isn't risky to allow end users to create databases. ... it is no more risky than giving you the ability to create spreadsheets. ... I'm not saying that Oracle and IBM are going away. ...
    (microsoft.public.excel)