Hi..
I hav a database for maintaining emp details. I want to get my EmpID to be generated automatically when my add new button is clicked. That too in C# only...

hi,

u can use ideintity for the column u want to increment empid.
u have to set identity in the column properties as 1.

The best method to do this is in your DateBase Table.
Add a primary key ID field of type integer with identity specification set to true. It will increment your ID field on each row insert

In VB i used the below coding for generating number automatically. It worked.
But in C# i cant able check whtr the database in null or not. Is thr any option?

If dr.Read() Then
If IsDBNull(dr(0)) Then
txtempid.Text = "101"
Else
txtempid.Text = ds1.Tables(0).Rows(0).Item(0) + 1
'Where ds contains the max value of the empid
End If
End If

in c# code

{ 
    if (dr.Read()) { 
        if (dr(0) == System.DBNull.Value) { 
            txtempid.Text = "101"; 
        } 
        else { 
            txtempid.Text = ds1.Tables(0).Rows(0).Item(0) + 1; 
        } 
        //Where ds contains the max value of the empid 
    } 
}

in order to convert vb to c# u can use this tool
http://www.developerfusion.com/tools/convert/vb-to-csharp/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.