Retrieve The Autonumber Value In Access Using C#

  • Thread starter Thread starter Kabouter Smal
  • Start date Start date
K

Kabouter Smal

It's driving me crazy.....
How do i get The Autonumber Value of a record that is just inserted?
And then specialy in de Visual Studio.Net 2003 envoirement?
With the sqlCommand or DataSet in c#?

Please give me some ideas???

Regards,
Jake
 
Hi Kaboutertje

You have a link from Bill, however to make it easier for you, update it
every time you have added a new row and don't forget to do after that
immidiatly a fill again.

I hope this helps?

Cor
 
I was working all of the day to get this done.
I was Using the Query builder to get an insert query(very wrong to do)

Visual Studio does it for me when a drag a Table to my page.
No need to change the query!
And with the ExecuteScalar command i can retrieve the auto number.

INSERT INTO person
(Name)
VALUES (@name);
SELECT id, Name
FROM Person
WHERE (id = @@IDENTITY)


I have a dataAdapter named "da".
Then i did this:

private void Button1_Click(object sender, System.EventArgs e)
{
da.InsertCommand.Parameters[0].Value=txtName.Text ;
con.Open();
int Getid =(int) da.InsertCommand.ExecuteScalar();
con.Close();
Response.Write(Getid.ToString());
}


Where the hell can i get a good manual about Visual Studio.NET 2003?
This could me save me hours of time.

Regards,
Jake
 
In this regard I'm guessing you want info about ADO.NET.. David Sceppa's
ADO.NET Core Reference is a must have, as is Bill Vaughn's ADO & ADO.NET
Best Practices. Buy them both, they are cheap at any price

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Kabouter Smal said:
I was working all of the day to get this done.
I was Using the Query builder to get an insert query(very wrong to do)

Visual Studio does it for me when a drag a Table to my page.
No need to change the query!
And with the ExecuteScalar command i can retrieve the auto number.

INSERT INTO person
(Name)
VALUES (@name);
SELECT id, Name
FROM Person
WHERE (id = @@IDENTITY)


I have a dataAdapter named "da".
Then i did this:

private void Button1_Click(object sender, System.EventArgs e)
{
da.InsertCommand.Parameters[0].Value=txtName.Text ;
con.Open();
int Getid =(int) da.InsertCommand.ExecuteScalar();
con.Close();
Response.Write(Getid.ToString());
}


Where the hell can i get a good manual about Visual Studio.NET 2003?
This could me save me hours of time.

Regards,
Jake





Hi Kaboutertje

You have a link from Bill, however to make it easier for you, update it
every time you have added a new row and don't forget to do after that
immidiatly a fill again.

I hope this helps?

Cor
 
Back
Top