try,
I have hard coded the starting number as 160 and change accordingly and hope the code is self explanatory
private void button1_Click(object sender, EventArgs e)
{
try{
using (OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DATABASE\\Database1.mdb"))
{
thisConnection.Open();
OleDbCommand thisCommand = thisConnection.CreateCommand();
OleDbDataAdapter thisAdapter = new OleDbDataAdapter("select ID from WPID", thisConnection);
DataSet ods = new DataSet();
thisAdapter.Fill(ods);
OleDbCommandBuilder thisCommandBuilder = new OleDbCommandBuilder(thisAdapter);
for (int i=0; i < ods.Tables[0].Rows.Count;i++)
{
ods.Tables[0].Rows[i]["ID"] = 160 + i;
}
thisAdapter.Update(ods.Tables[0]);
MessageBox.Show("OK");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
UPDATE -1 Solution added later based on OP's comment and revises the above solution.
private void button3_Click(object sender, EventArgs e)
{
try
{
using (OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DATABASE\\Database1.mdb"))
{
thisConnection.Open();
OleDbCommand thisCommand = thisConnection.CreateCommand();
OleDbDataAdapter thisAdapter = new OleDbDataAdapter("select ID,WPID from table1", thisConnection);
DataSet ods = new DataSet();
thisAdapter.Fill(ods);
OleDbCommandBuilder thisCommandBuilder = new OleDbCommandBuilder(thisAdapter);
int intStart = 3003;
int intEnd = 3010;
for (int i = 0; i < ods.Tables[0].Rows.Count; i++)
{
ods.Tables[0].Rows[i]["WPID"] = intStart;
intStart = intStart + 1;
}
while (intStart <= intEnd)
{
DataRow x = ods.Tables[0].NewRow();
x["WPID"] = intStart;
x["ID"] = "Blank" + intStart;
ods.Tables[0].Rows.Add(x);
intStart = intStart + 1;
}
thisAdapter.Update(ods.Tables[0]);
MessageBox.Show("OK");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}