LastInsertID - Maybe im a dumb! :P
LastInsertID - Maybe im a dumb! :P
Hi,
Im used to code with mySQL from PHP and for retrieve the LastID from a table after an Insert usually I did a table with counters to assure it on a multiuser environment.
But now, sad, im coding an app for .Net, and using directly the commands from your library there is no problem to do it, its easy as well you put it in a public var.
But now im trying to get it after a Adapter update.
Easy code:
- Binding addnew
- A form filled from scrath, with binding to a ds.
- Binding endupdate
- TableAdaptor Update
- And then...
Dunno whats the best way to get the last inserted id form there, think it should be easy but cant find solution, thinking i dont wanna do a ugly code doing a nasty select.. etc...
Can you show me the light and give me the best easier solution for it, thinking that it can be a multiuser app.
Thanx in advance,
Im used to code with mySQL from PHP and for retrieve the LastID from a table after an Insert usually I did a table with counters to assure it on a multiuser environment.
But now, sad, im coding an app for .Net, and using directly the commands from your library there is no problem to do it, its easy as well you put it in a public var.
But now im trying to get it after a Adapter update.
Easy code:
- Binding addnew
- A form filled from scrath, with binding to a ds.
- Binding endupdate
- TableAdaptor Update
- And then...
Dunno whats the best way to get the last inserted id form there, think it should be easy but cant find solution, thinking i dont wanna do a ugly code doing a nasty select.. etc...
Can you show me the light and give me the best easier solution for it, thinking that it can be a multiuser app.
Thanx in advance,
Code: Select all
select last_insert_id();
I did it already, I knew it, just i was wondering because Visual Studio is doing the update via adaptor i thought it has those function. Also when you configure the adaptor Visual Studio asked me about do it saying something like "Do you want to Visual Studio makes a Select after insert update to retrieve identity field".... I said YES, but i dont know where is that data which he says will retrieve.
Accesing private properties in a TableAdapter
I am using .net 2.0. The TableAdapter class is a partial class (and you have the source code for it) so you can add any additional functionality to it. Simply create (and include in your project) a file containing whatever code you want to add to the class.
The following code adds public properties for the InsertID of the Command objects. (Look in your xxxDataSet.Designer.cs file for the name of the class and the namespace for your TableAdapter.)
Then you can access them like this after updating the dataset:
long insertID = this.xxxTableAdapter.InsertID;
Happy Trying,
The following code adds public properties for the InsertID of the Command objects. (Look in your xxxDataSet.Designer.cs file for the name of the class and the namespace for your TableAdapter.)
Code: Select all
namespace xxx.xxxDataSetTableAdapter
{
public partial class xxxTableAdapter
{
public long InsertID
{
get
{
return (this._adapter.InsertCommand.InsertId);
}
}
}
}
long insertID = this.xxxTableAdapter.InsertID;
Happy Trying,