Someone can tell me where i m doing mistake in order to show Autogenerate Id everytime with increasing of one.

string conn = @"Data Source=FARHAD-PC\SQLEXPRESS;Initial Catalog=shop;Integrated Security=True";
            myconnection = new SqlConnection(conn);
            myconnection.Open();

            string query_Id = "select * from tblEmployee";
            mydataadapter = new SqlDataAdapter(query_Id, myconnection);
            mydataset = new DataSet();
            mydataadapter.Fill(mydataset);

            try
            {

                int index = (int) mydataset.Tables[0].Rows.Count - 1;
                iRegNo = (int)mydataset.Tables[0].Rows[index].ItemArray[1] + 1;
                txtID.Text = iRegNo.ToString();
            }

            catch (IndexOutOfRangeException iore)
            {
                txtID.Text = "1";
            }

everytime error showing is specified cast is not valid.
:(
whats problem?
Regards...

You should set the column as auto and you don't have to worry about it. Other than that, we can't tell how you've defined the table, so can't tell if you have the right column, what type it is, etc.

Use

Select max(id) from tblemployee

, to get the highest id column..

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.