i would facing a problem while working in C#. AS i have to generate an ID which is automatically when user clicks on ADD button
A:
If you can modify the schema, do what @John Saunders says. If you have to make your own identify for some reason, try using a GUID.
Guid g = Guid.NewGuid();
Blair Conrad
2010-02-06 13:05:09
+3
A:
If I understand your question, you will be adding a row to a database table when the user clicks an ADD button, and you want the row to get an automatically-generated ID.
Simply add an IDENTITY column. You should probably make it the primary key, as well:
CREATE TABLE [dbo].[Table_1](
[ID] [int] IDENTITY(1,1) NOT NULL,
[MORE_DATA] [nvarchar](50) NULL
)
John Saunders
2010-02-06 13:07:51
Probably not relevant to the OP, but note that using identity columns like this has problems with scaleability (with respect to merge replication), you may be better off using a guid (set as uniqueidentifier).
David_001
2010-02-06 16:27:11
Is merge replication the only scalability issue with identity columns?
John Saunders
2010-02-06 18:41:23