4
Reply

how to create employee code automatically using sqlserver as database and asp,net using C#

Goutam kundu

Goutam kundu

May 16, 2010
11k
0

     

     WHEN WE DEFINE DATATYPE THEN WRITE

    employeeid IDENTITY(1,1)

    kiran adhLAKHA
    May 20, 2010
    0

    try
                {
                    string connStr = "Data Source=DEV1;Initial Catalog=SuperRental;Integrated Security=SSPI;";
                    using (SqlConnection conn = new SqlConnection(connStr))
                    {
                        conn.Open();
                        string sqlQuery = "INSERT INTO tbl_employee (EmployeeName) VALUES ('Sardar'); SELECT @@identity";
                        using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
                        {
                            object obj_employeeCode = cmd.ExecuteScalar();
                            int employeeCode = int.Parse(obj_employeeCode.ToString());

                            System.Console.WriteLine("New Employee code is : " + employeeCode);
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }

    May 20, 2010
    0

    You can do that easily by going into your datatable ,select the employee code column . On the column properties select Yes for the IsIdentity property .set the identity increament to the step you want each number to auto increament with . this way everytime you enter / create an employee entry the employee code auto increaments .

    I do hope this helps.

    zxcoder
    May 18, 2010
    0

    con.open();
    string r = "select max(substring(empid,5,5))from employee";
    cmd=new sqlcommand(str,con);
    sqldatareader dr;
    dr=cmd.executenonquery();
    int d = Convert.ToInt32(r);
    int k = d + 1;

    if (dr.Read() == true)


    {
       
        textbox1.text="emp0"+k;
    }
    con.close();

    getcy paulraj
    May 18, 2010
    0