Lombard Lombard - 7 months ago 24
Vb.net Question

What "Tab" of "Tab.Columns" means on this code

Im trying to translate to vb the c# code i found in Here. I was pretty successfull but having troubles with "Tab" in "foreach(DataColumn C in Tab.Columns)"

Aparently its not a global variable... but he didnt define it in nowhere.

The method is this one:

private void My_OnRowUpdate(object sender, OleDbRowUpdatedEventArgs e)
{
if(e.StatementType==StatementType.Insert)
{
// reads the identity value from the output parameter @ID
object ai = e.Command.Parameters["@ID"].Value;

// updates the identity column (autoincrement)
foreach(DataColumn C in Tab.Columns)
{
if(C.AutoIncrement)
{
C.ReadOnly = false;
e.Row[C] = ai;
C.ReadOnly = true;
break; // there can be only one identity column
}
}

e.Row.AcceptChanges();
}
}


May i missundesrtood something?

Thanks

Answer

Since the RowUpdated event passes the OleDbRowUpdatedEventArgs as argument you can simply use it's Row property to get a reference to the table. That's better than in the article:

private void My_OnRowUpdate(object sender, OleDbRowUpdatedEventArgs e)
{             
   if(e.StatementType==StatementType.Insert) 
   {                
      // reads the identity value from the output parameter @ID
      object ai = e.Command.Parameters["@ID"].Value;

      // updates the identity column (autoincrement)                   
      foreach(DataColumn C in e.Row.Table.Columns)
      {
         if(C.AutoIncrement)
         {
            C.ReadOnly = false;                      
            e.Row[C] = ai;  
            C.ReadOnly = true;
            break; // there can be only one identity column
         }      
      }                        

      e.Row.AcceptChanges();             
   }
}
Comments