Click here to Skip to main content
15,300,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am new in c sharp, working on windows application where i need to increase student id automatically in database. And it should come directly in combo box when i open the particular form to add data, related to student.

thanks in advance.

Your database management software should be able to set the ID column to AutoIncrement. You can then create a new data row and let the database provide the ID. After that, you re-read and change what is necessary but leave ID untouched at all times.
mkcm2011 3-Nov-11 4:35am
i am working on sql server 2005 and AutoIncrement is not available there.
public string SlNo(string tblName, string colName, string srchCodn, Page form)
        string functionReturnValue = null;
            string sqlQuery = "select max(" + colName + ") + 1 from " + tblName;
            if (srchCodn != "")
                sqlQuery += " " + srchCodn;
            adp = new SqlDataAdapter(sqlQuery, conn);
            tbl = new DataTable();
            if (tbl.Rows.Count == 0 | tbl.Rows[0][0].ToString() == "")
                functionReturnValue = Convert.ToString(1);
                functionReturnValue = tbl.Rows[0][0].ToString();
        catch (Exception ex)
            MsgBox("Serial No Error: " + ex.Message, form);
            return "";
        return functionReturnValue;

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