Stored procedure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nbohana

    Stored procedure

    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 SubmitChangesVi aDataAdapter()
    {
    IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandD etail' AND
    user_name(uid) = 'dbo')
    DROP PROCEDURE [dbo].[InsertCommandDe tail];
    GO

    CREATE PROCEDURE [dbo].[InsertCommandDe tail]
    {
    @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
  • Nick Malik [Microsoft]

    #2
    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:[color=blue]
    > INSERT INTO services([service-code], [service-description],
    > [large-animal-cost], [medium-animal-cost], [small-animal-cost]) VALUES
    > (@Param1, @Param2, @Param3, @Param4, @Param5, @filler);[/color]

    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:[color=blue]
    > 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];[/color]

    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 'uniqueidentifi er' 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


    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@discus sions.microsoft .com> wrote in message
    news:DEF88E77-088E-48DD-B719-790A40F61038@mi crosoft.com...[color=blue]
    >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 SubmitChangesVi aDataAdapter()
    > {
    > IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandD etail' AND
    > user_name(uid) = 'dbo')
    > DROP PROCEDURE [dbo].[InsertCommandDe tail];
    > GO
    >
    > CREATE PROCEDURE [dbo].[InsertCommandDe tail]
    > {
    > @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[/color]


    Comment

    • nbohana

      #3
      Re: Stored procedure

      Thanks Nick, I actually did create them in the sql server, I just didn't how
      to use them.


      "Nick Malik [Microsoft]" wrote:
      [color=blue]
      > 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:[color=green]
      > > INSERT INTO services([service-code], [service-description],
      > > [large-animal-cost], [medium-animal-cost], [small-animal-cost]) VALUES
      > > (@Param1, @Param2, @Param3, @Param4, @Param5, @filler);[/color]
      >
      > 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:[color=green]
      > > 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];[/color]
      >
      > 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 'uniqueidentifi er' 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@discus sions.microsoft .com> wrote in message
      > news:DEF88E77-088E-48DD-B719-790A40F61038@mi crosoft.com...[color=green]
      > >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 SubmitChangesVi aDataAdapter()
      > > {
      > > IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandD etail' AND
      > > user_name(uid) = 'dbo')
      > > DROP PROCEDURE [dbo].[InsertCommandDe tail];
      > > GO
      > >
      > > CREATE PROCEDURE [dbo].[InsertCommandDe tail]
      > > {
      > > @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[/color]
      >
      >
      >[/color]

      Comment

      Working...