Re: SCOPE_IDENTITY() in c# and no stored procedure...
- From: "TrintCSD" <TrintCSD@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 10 May 2005 10:40:12 -0700
ok, I do not understand how to get a value into a stored procedure from my c#
string, int or whatever datatype. It's much easier for me to do it as you
can see in the "VALUES" part of the command with strings. What does the
VALUES look like when you create a stored procedure for insert if you don't
have the values yet.
When you call the stored procedure:
catDA.InsertCommand = new SqlCommand("GetParameterIdentity", strConn);
catDA.InsertCommand.CommandType = CommandType.StoredProcedure;
How do my values from textboxes, calculations and all over the place get in
there?
>From all I've seen, values look like the field names with an @ sign in front
of them.
An example would probably help.
Thanks for any replies.
Trint
"gabe garza" wrote:
>
> > string strSQL5 = "INSERT INTO tblTravelDetail(MemberId, " +
> > " Comments, " +
> > " TravelEventId, " +
> > " OrderId, " +
> > " ItemID, " +
> > " PeriodID, " + //here is where we do the PeriodID lookup calculation
> > " CreatedDateTime, " +
> > " Operator) " +
> > "VALUES ('" + deiinsertString2 + "', " +
> > " '" + deiinsertString3 + "', " +
> > " '" + eiinsertString1 + "', " +
> > " '" + deiinsertString5 + "', " +
> > " '" + deiinsertString6 + "', " +
> > " '" + deiinsertString7 + "', " +
> > " '" + deiinsertString8 + "', " +
> > " '" + insertString7 + "') "
> > cnn5.Execute(strSQL5);
>
> > strSQL5 = "SELECT SCOPE_IDENTITY()"
> > cnn5.Execute(strSQL5);
>
> Using the same cnn5 connection you can retrieve your SCOPE_IDENTITY() from
> your previous INSERT.
> But it must be the same SqlConnection, don't create another SqlConnection,
> use cnn5 on both Execute()'s.
>
> I think someone pointed out that you should really be using a parameterized
> sql query or even better, do this in a stored procedure and have the
> identity return in an OUTPUT Parameter or as a RETURN from your stored
> procedure.
>
>
> "TrintCSD" <TrintCSD@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:C13DFFCD-546D-458C-8FDA-C4B391120085@xxxxxxxxxxxxxxxx
> > ok, I've been on this for a long time...How can I get the most recent
> > identity from this insert into a string?(with using this code as the
> > insert):
> >
> > string strSQL5 = "INSERT INTO tblTravelDetail(MemberId, " +
> > " Comments, " +
> > " TravelEventId, " +
> > " OrderId, " +
> > " ItemID, " +
> > " PeriodID, " + //here is where we do the PeriodID lookup calculation
> > " CreatedDateTime, " +
> > " Operator) " +
> > "VALUES ('" + deiinsertString2 + "', " +
> > " '" + deiinsertString3 + "', " +
> > " '" + eiinsertString1 + "', " +
> > " '" + deiinsertString5 + "', " +
> > " '" + deiinsertString6 + "', " +
> > " '" + deiinsertString7 + "', " +
> > " '" + deiinsertString8 + "', " +
> > " '" + insertString7 + "'); " +
> > "SELECT SCOPE_IDENTITY()";
> >
> > cnn5.Execute(strSQL5, out recordsEffected, 0);
> >
> > Thanks,
> > Trint
> >
> > --
> > Trinity Smith
> > c#/vb.Net Developer
> > EcoQuest, Intl.
>
>
>
.
- Follow-Ups:
- Re: SCOPE_IDENTITY() in c# and no stored procedure...
- From: gabe garza
- Re: SCOPE_IDENTITY() in c# and no stored procedure...
- References:
- SCOPE_IDENTITY() in c# and no stored procedure...
- From: TrintCSD
- Re: SCOPE_IDENTITY() in c# and no stored procedure...
- From: gabe garza
- SCOPE_IDENTITY() in c# and no stored procedure...
- Prev by Date: Re: OleDbConnection
- Next by Date: Re: Problem checking data type of a db column
- Previous by thread: Re: SCOPE_IDENTITY() in c# and no stored procedure...
- Next by thread: Re: SCOPE_IDENTITY() in c# and no stored procedure...
- Index(es):
Relevant Pages
|