c# 操作Oracle 数据库问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 11:22:49
我想删除已行数据,操作能够完成,但是不知道哪里出问题不能保存到数据库中?!怀疑是DataRowCollection rowcol = t1.Rows;这句!
还有就是rowcol.Remove(t1.Rows[2]),怎么选择删除最下面的数据?

说明:数据库连接没有问题,能够增加修改数据。
这是我的代码:
private void button4_Click(object sender, EventArgs e)
{
OracleCommandBuilder buider = new OracleCommandBuilder(adapter);

DataTable t1 = set.Tables["table1"];
DataRowCollection rowcol = t1.Rows;
rowcol.Remove(t1.Rows[2]);
adapter.Update(set, "table1");
}
谢谢!
问题应该不是这里,我显示DataRowCollection和t1.Rows里的row的数量都是一样的
MessageBox.Show("DataRowCollection的count:" + rowcol.Count.ToString() +",t1.Rows的count:" + t1.Rows.Count.ToString());
但是我看.net帮助文档里的例子,直接remove可以了
这是例子:
Private Sub RemoveFoundRow(ByVal table As DataTable)
Dim rowCollection As DataRowCollection = table.Rows

' Test to see if the coll

DataTable t1 = set.Tables["table1"];
DataRowCollection rowcol = t1.Rows;
你这里用一个新的变量来存放从t1中取得的值有什么用呢?
直接调用DataTable对象的Rows属性不就能得到它的Row集合了吗?
而且你在这里只是从rowcol中将第三行删除了,而t1中的行是没有任何改变的,所以你没有更新成功。
直接使用t1.Rows.Remove(t1.Rows[2]);