如何在 C# 中从用户网格视图中获取行
本文关键字:网格 视图 获取 用户 | 更新日期: 2023-09-27 18:37:19
当我想使用 C# 中的 OleDB 将内容从用户网格视图添加到访问数据库中时,我有以下代码:
da.InsertCommand = new OleDbCommand("INSERT INTO [some] ([some1], [some2]) VALUES (?,?)");
da.InsertCommand.Parameters.Add("@some1", OleDbType.VarChar, 60, "some1");
da.InsertCommand.Parameters.Add("@some2", OleDbType.VarChar, 60, "some2");
据我所知,我们InsertCommands
末尾的some1
和some2
是我usergridview
中的列.现在我想实现的是先编辑内容,然后再将其插入数据库。所以我的实际问题是我怎样才能在InsertCommand
之外获得"some1
"以将其放入函数中(例如my_function(some1)
应该是参数内容)。
这是一些伪语法
public void my_function(string varSome1, string varSome2)
{
.
.
OleDbCommand cmd = new OleDbCommand("INSERT INTO [some] ([some1], [some2]) Values (@some1, @some2)", yourOleDbConnection);
cmd.Parameters.AddWithValue("@some1", varSome1);
cmd.Parameters.AddWithValue("@some2", varSome2);
.
.
.
da.InsertCommand = cmd;
.
.
}
编辑
从其他函数编辑值
string editedSome1 = "your edited value1";
string editedSome2 = "your edited value2";
然后你打电话
my_function(editedSome1, editedSome2);