John Joe

John Joe

  • NA
  • 81
  • 15.9k

counting row and increment primary key with the next row

Apr 17 2013 5:00 AM

Here is my code: ( It is not working)

sc.Open();
            cmd = new SqlCommand("SELECT COUNT (*) FROM Records", sc);


            Int32 count = (Int32)cmd.ExecuteScalar();

            if (count >= 0)

                for (int i = 1; i < count; i++)            
              cmd = new SqlCommand("Insert into Records(Num, Faculty, Intake, Location, Years, University, Fees, Courses) values('" +1+ "','" + DropDownList5.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "','" + DropDownList4.SelectedItem.Text + "','" + DropDownList6.SelectedItem.Text + "','" + DropDownList7.SelectedItem.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "')", sc);
               sc.Close();

Answers (4)