0

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...

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Randlathor05
0

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.

0

Use

Select max(id) from tblemployee

, to get the highest id column..

Edited by Randlathor05

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.