DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 14 May 2007 18:35:30 -0500,    posted on: microsoft.public.dotnet.framework.odbcnet        back       

Thread Index
  1    Beemer Biker
          2    Riki st
          3    Riki st
          4    MasterGaurav \(www.edujini-labs.com\)
          5    MasterGaurav \(www.edujini-labs.com\)


is there a "last id" mechanism on an update?   
I have a gridview "new" command that insert a new row into a postgresql 
database.that uses the odbc driver.

Newbie as I am i thought that iReturn would have the new index that was 
created.

SqlDS1.InsertCommand = "INSERT INTO \"Algorithms\" (source_code_id,  comment 
VALUES (69, 'haleys comet', 1)";

int iResult = SqlDS_Algorithms.Insert();

Ok, instead of getting back an id I got back a "1" which just indicates the 
command ran ok.  Looking at the database I see the new id value and it is 
318.  Is there some mechanism I can use to obtain the index value that was 
autogenerated?

googleing around I see where some people are writing stored procedures and I 
see one here:

http://www.thescripts.com/forum/thread173510.html



Was just wondering if the is a way to use the gridview or sqldataset1 
control to get that index value and avoid writing a stored procedure.



...thanks..


-- 
======================================================================
Joseph "Beemer  Biker" Stateson
http://ResearchRiders.org     Ask about my 99'R1100RT
======================================================================
Date:Mon, 14 May 2007 18:35:30 -0500   Author:  

Re: is there a "last id" mechanism on an update?   
"Beemer Biker"  wrote in message 
news:134hsi499grbg21@corp.supernews.com...

>I have a gridview "new" command that insert a new row into a postgresql 
>database.that uses the odbc driver.
>
> Newbie as I am i thought that iReturn would have the new index that was 
> created.
>
> SqlDS1.InsertCommand = "INSERT INTO \"Algorithms\" (source_code_id, 
> comment VALUES (69, 'haleys comet', 1)";
>
> int iResult = SqlDS_Algorithms.Insert();
>
> Ok, instead of getting back an id I got back a "1" which just indicates 
> the command ran ok.  Looking at the database I see the new id value and it 
> is 318.  Is there some mechanism I can use to obtain the index value that 
> was autogenerated?
>
> googleing around I see where some people are writing stored procedures and 
> I see one here:
>
> http://www.thescripts.com/forum/thread173510.html
>
>
>
> Was just wondering if the is a way to use the gridview or sqldataset1 
> control to get that index value and avoid writing a stored procedure.


There is.
Still you need a "mini" stored procedure.
Just extend your INSERT command on the datasourcecontrol as follows:
"INSERT INTO myTable (x,y,z) VALUES (@x,@y,@y);SELECT @newID = @@IDENTITY;"

Then add an additional parameter @newID to your datasourcecontrol's 
InsertParameters, marking it as Direction="output" instead of the default 
input.

In the OnInserted event of the datasourcecontrol, you can get the value of 
this parameter with e.Command.Parameters("@newID").Value.

In Sql Server 2005, SELECT @@IDENTITY can be replaced by
SELECT SCOPE_IDENTITY() which is a little bit better.

Riki
Date:Tue, 15 May 2007 15:16:05 +0200   Author:  

Re: is there a "last id" mechanism on an update?   
"Beemer Biker"  wrote in message 
news:134hsi499grbg21@corp.supernews.com...

>I have a gridview "new" command that insert a new row into a postgresql 
>database.that uses the odbc driver.
>
> Newbie as I am i thought that iReturn would have the new index that was 
> created.
>
> SqlDS1.InsertCommand = "INSERT INTO \"Algorithms\" (source_code_id, 
> comment VALUES (69, 'haleys comet', 1)";
>
> int iResult = SqlDS_Algorithms.Insert();
>
> Ok, instead of getting back an id I got back a "1" which just indicates 
> the command ran ok.  Looking at the database I see the new id value and it 
> is 318.  Is there some mechanism I can use to obtain the index value that 
> was autogenerated?
>
> googleing around I see where some people are writing stored procedures and 
> I see one here:
>
> http://www.thescripts.com/forum/thread173510.html
>
>
>
> Was just wondering if the is a way to use the gridview or sqldataset1 
> control to get that index value and avoid writing a stored procedure.


There is.
Still you need a "mini" stored procedure.
Just extend your INSERT command on the datasourcecontrol as follows:
"INSERT INTO myTable (x,y,z) VALUES (@x,@y,@y);SELECT @newID = @@IDENTITY;"

Then add an additional parameter @newID to your datasourcecontrol's 
InsertParameters, marking it as Direction="output" instead of the default 
input.

In the OnInserted event of the datasourcecontrol, you can get the value of 
this parameter with e.Command.Parameters("@newID").Value.

In Sql Server 2005, SELECT @@IDENTITY can be replaced by
SELECT SCOPE_IDENTITY() which is a little bit better.

Riki
Date:Tue, 15 May 2007 15:16:05 +0200   Author:  

Re: is there a "last id" mechanism on an update?   

>> int iResult = SqlDS_Algorithms.Insert();
>>
>> Ok, instead of getting back an id I got back a "1" which just indicates 
>> the command ran ok.  Looking at the database I see the new id value and 
>> it is 318.  Is there some mechanism I can use to obtain the index value 
>> that was autogenerated?


Well, it returns the number of rows affected! And that's what you get as the 
iResult.

Follow what you got from thescripts-article or what Riki wrote. That's the 
sole way out.


-- 
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
Date:Mon, 4 Jun 2007 14:27:30 +0530   Author:  

Re: is there a "last id" mechanism on an update?   

>> int iResult = SqlDS_Algorithms.Insert();
>>
>> Ok, instead of getting back an id I got back a "1" which just indicates 
>> the command ran ok.  Looking at the database I see the new id value and 
>> it is 318.  Is there some mechanism I can use to obtain the index value 
>> that was autogenerated?


Well, it returns the number of rows affected! And that's what you get as the 
iResult.

Follow what you got from thescripts-article or what Riki wrote. That's the 
sole way out.


-- 
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
Date:Mon, 4 Jun 2007 14:27:30 +0530   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us