Click here to Skip to main content
15,349,320 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to retrieve an auto number value from the ms-access database table from column name "id" using c# is
and then I want to convert that auto number value to "ToInt64" as a string value.
I have tried this but these queries are not working please do help me if you have any idea about that

Int64 pid = Convert.ToInt64(Request.QueryString["id"]);

What I have tried:

please free to write any type of suggestion or Queries which I can try on my code
Updated 24-Aug-21 2:01am
Richard MacCutchan 24-Aug-21 6:52am
You first need to extract the value from the database with a SELECT statement.

1 solution

And autonumber column is the same as any other column, except you can't write to it yourself.

So a normal SELECT will retrieve it. If you are trying to INSERT a new row and then get the number that was assigned, then
SELECT @@Identity
immediately after the INSERT will do it.
If you use ExecuteScalar instead of ExecuteReader or DataAdapter.Fill then you can just cast the result to an integer:
int lastNo = (int) myCommand.ExecuteScalar();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900