Windows 为什么不是';t我的数据适配器->;是否更新正在处理的新表单?
我有一个主窗体。有一个链接标签。如果我点击它,就会打开一个新表单,上面有一个datagrid和一个按钮。datagrid将填充新表单加载事件的数据。 我以这种方式绑定数据源:Windows 为什么不是';t我的数据适配器->;是否更新正在处理的新表单?,windows,visual-c++,c++-cli,Windows,Visual C++,C++ Cli,我有一个主窗体。有一个链接标签。如果我点击它,就会打开一个新表单,上面有一个datagrid和一个按钮。datagrid将填充新表单加载事件的数据。 我以这种方式绑定数据源: void BindDataSource( BindingSource^ BS, SqlDataAdapter^ DA, DataGridView^ DG, String^ SQLCommand ) { DG->DataSource = BS; //InsertDataToDataGrid( "select * fr
void BindDataSource( BindingSource^ BS, SqlDataAdapter^ DA, DataGridView^ DG, String^ SQLCommand )
{
DG->DataSource = BS;
//InsertDataToDataGrid( "select * from myTable", dataGridView10 );
String^ connectionString = "database=myDataBase;server=myServer;UID=UserID;PWD=Password;";
// Create a new data adapter based on the specified query.
DA = gcnew SqlDataAdapter( SQLCommand, connectionString);
gcnew SqlCommandBuilder( DA );
DataTable^ table = gcnew DataTable();
DA->Fill( table );
BS->DataSource = table;
}//BindDataSource
如果我点击按钮,它将保存更改
我这样保存:dAPcExceptions->Update((DataTable^)bSPCExceptions->DataSource)代码>
我在主窗体上使用此方法,效果很好。
但是,如果单击该按钮,则会出现错误:
update在传递带有修改行的数据行集合时需要有效的updatecommand
有人能告诉我我做错了什么吗
谢谢 我想您应该创建一个SqlDataAdapter,并将其重新存储以备将来使用。因此,必须使用轨迹引用将SqlDataAdapter参数作为输入/输出
void BindDataSource( BindingSource^ BS, SqlDataAdapter^% DA, DataGridView^ DG, String^ SQLCommand )
{
...
// Create a new data adapter based on the specified query.
DA = gcnew SqlDataAdapter( SQLCommand, connectionString);
...
}//BindDataSource