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);

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


                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?

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.


Select max(id) from tblemployee

, to get the highest id column..