我正在尝试将我在C#中找到的这里代码翻译到VB中。我很成功,但在foreach(DataColumn C in Tab.Columns)
上遇到了foreach(DataColumn C in Tab.Columns)
的麻烦。
显然这不是一个全局变量..。但他没有给它下任何定义。
方法是这样的:
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();
}
}
也许我误解了什么?
发布于 2016-04-28 10:58:20
由于RowUpdated
事件将OleDbRowUpdatedEventArgs
作为参数传递,所以您可以简单地使用它的Row
属性获取对表的引用。这比文章要好得多:
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();
}
}
https://stackoverflow.com/questions/36912462
复制相似问题