Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
How to create autonumber function for a database using c#. Provide the clear code only in c#
Posted

1 solution

All you have to do is connect to your DB in the usual way, and create an SqlCommand such as:
USE [MyDataBaseName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MyTable](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nchar](10) NOT NULL,
) ON [PRIMARY]
GO
Then call ExecuteNonQuery.

P.S. If you had been a little polite, you might have got a better solution.
We do not work for you, we do not get paid to do this, and rude arrogance like you show will not get you far.
 
Share this answer
 
Comments
Sebastian T Xavier 26-Jun-12 2:50am    
my +5
P.Vinoth 26-Jun-12 4:05am    
i need that to be created in c#. I already Created an client_info database i need to assign client_id as autonumber through c# coding. If i insert a record its keep on increasing
P.Vinoth 26-Jun-12 4:58am    
i didn't asked you to post the answer quickly if you know the answer post it otherwise stay away . you always post the irrelevant answers. i didn't compel you to post the answer . Use the words correctly
OriginalGriff 26-Jun-12 5:05am    
Oh, I know the answer.
But your attitude does not encourage me to spend my time helping you in this case.
Perhaps you should rethink how you approach people when you want help from them?
Just a thought.
P.Vinoth 26-Jun-12 5:30am    
whats wrong in my approach. oh you want me to beg you for the answer.

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