Last post Jun 10, 2011 11:05 AM by Mikesdotnetting
Jun 06, 2011 09:43 AM|melvintcs|LINK
i have a primary key where its a autonumber, by default the database auto increase the integer by 1.
how to change the format to ABC1, ABC2, ABC3, ABC4 ...
(using MS access)
thanks in advance :)
Jun 06, 2011 09:52 AM|bouwob2|LINK
I do not believe that this is possible. The purpose of an identity is to allow the database to do the numbering for you. While it would be easy to code, having to split the string, increase
the count, then concat the string back together on every row to figure out the highest number would be a lot of work.
Check out this thread for customization with the identity column
Jun 07, 2011 09:47 PM|Decker Dong - MSFT|LINK
If you only want to show it on UI ---- I mean that only it's for appearance. You can do this:
1) Set the column (let's say "Id" to Identified column stepped by 1 from 1).
2) Bind in the TemplateField in the GridView like this:
Jun 09, 2011 06:59 AM|KumarHarsh|LINK
Suppose I hv a table called Emp (id (autonumber),name (text),empid (text))
Here i took id in order to test.
I write this query in mdb query window
INSERT INTO emp (name,empid)Select 'gfhfgh', 'ABC'&max(id)+1 from empIt append record. Wht is ur table design ? in place of 'gfhfgh' you can use your parameter variable.
Jun 10, 2011 01:48 AM|KumarHarsh|LINK
Two column namely col1 (pk text),col2 (text)
where col1 will contain ABC1,ABC2........etc
while insert in table1 i write query
insert into table1(col1,col2)SELECT 'ABC' & max(replace(col1,'ABC',''))+1,'fgdf' from table1
Jun 10, 2011 11:05 AM|Mikesdotnetting|LINK
As others have said, this is not possible. There are workarounds: you could just use string.Format for display purposes as Decker suggested, or you could add another column and generate your own ID value from the Autonumber that Access generates:
string query = "Insert Into Categories (CategoryName) Values (?)";
string query2 = "Select @@Identity";
string query3 = "UPDATE Categories SET MyCustomId = ?";
string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data ource=|DataDirectory|Northwind.mdb";
using (OleDbConnection conn = new OleDbConnection(connect))
using (OleDbCommand cmd = new OleDbCommand(query, conn))
cmd.CommandText = query2;
ID = (int)cmd.ExecuteScalar();
cmd.CommandText = query3;
cmd.Parameters.AddWithValue("", "ABC" + ID);