Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SqlCommand cd = new SqlCommand();
cd.CommandText = "select * from NONPRODUCTION_RESUME order by RESUMEID";
cd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cd);
SqlCommandBuilder m_SQLCmdBuilder = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "resid");
//ds.Tables["resid"].Constraints.Add("rid", ds.Tables["resid"].Columns["RESUMEID"], true);
int k = 1;
int var = 0;
        
for ( var = 0; var < ds.Tables["resid"].Rows.Count; var++)
{
  // DataRow dr=  
  ds.Tables["resid"].Rows[var]["RESUMEID"]=k;
  //dr.BeginEdit();
  //dr["RESUMEID"] = k;
  //dr.EndEdit();
  //dr.BeginEdit();
  //dr["RESUMEID"] = k;
  k++;
  //ds.Tables["resid"].GetChanges();
  da.Update(ds.Tables["resid"]);
  //ds.AcceptChanges();
}

I have the above code at where I am trying to rearrange the resume id after deleting middle rows.
But here I am getting an error like
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
Posted
Updated 17-Feb-11 21:15pm
v2

1 solution

Am I right in thinking that RESUMEID is the primary key for the table? And that it is an automatically incrementing integer?

If so, you can't change it. The database assigns them, the database maintains them. It will not let you change them.

Even if it would, it is a very bad idea to change a record ID at all. Consider this: you have two users, both execute your code at the same time. What ID is assigned? Are they all sequential?

No. Because one user has deleted record 14, and the other has deleted record 17. Neither knows about the other so they are both trying to give record 18 a different number. In fact, one of them has renumbered 17, so what the other deletes is actually record 18 anyway!

If you really need to use sequential numbering, then use the ordinal number of the record, rather than the ID: it is a lot safer, and does not need to be updated as it reflects the state of the database at that time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900