P
Pascalus
Hi there!
I've parsed the posts in this thread but haven't found answers to my problem. It drives me nuts.
I'm newbie at Database app under VS2003 and for now I only do simple things.
I fill a table with hundreds of records. I can see the result in a DataGrid.
Now I want to save the records on the physical file - the table - (through a SQL server).
How can I do that?
For the adapter, I dropped an oleDbAdapter on the form and followed the setup (a SQL connection).
I generated the dataset and the wizard generated all the INSERT/UPDATE/... commands without problem.
Below is a code snippet (C++ style). Can somebody tell me what's wrong/missing in it?
Many thanks,
/Pascalus.
----------------------
private: System::Void btnOK_Click(System::Object * sender, System::EventArgs * e)
{
DataTable *table = myDataSet->Tables->Item[S"myTable"];
table->Clear();
for(int i=0; i<num; i++) {
DataRow *newRow = table->NewRow();
newRow->BeginEdit(); // is this mandatory?
newRow->Item[S"Column1"] = <something>;
newRow->Item[S"Column2"] = <something>;
newRow->EndEdit();
table->Rows->Add(newRow);
}
table->AcceptChanges(); // if not called, I get a oleDbDataAdapter Exception afterwards
}
// then I call UpdateTable(myDataSet, S"myTable");
void UpdateTable(DataSet* dataSet, String* tableName)
{
this->BindingContext->get_Item(dataSet, tableName)->EndCurrentEdit();
oleDbDataAdapter1->Update(dataSet, tableName); // if DataGrid has been edited, then I get DBConcurrencyException
if(dataSet->HasChanges(DataRowState::Added)) { // apparently, returns always FALSE
dataSet->AcceptChanges();
}
}
I've parsed the posts in this thread but haven't found answers to my problem. It drives me nuts.
I'm newbie at Database app under VS2003 and for now I only do simple things.
I fill a table with hundreds of records. I can see the result in a DataGrid.
Now I want to save the records on the physical file - the table - (through a SQL server).
How can I do that?
For the adapter, I dropped an oleDbAdapter on the form and followed the setup (a SQL connection).
I generated the dataset and the wizard generated all the INSERT/UPDATE/... commands without problem.
Below is a code snippet (C++ style). Can somebody tell me what's wrong/missing in it?
Many thanks,
/Pascalus.
----------------------
private: System::Void btnOK_Click(System::Object * sender, System::EventArgs * e)
{
DataTable *table = myDataSet->Tables->Item[S"myTable"];
table->Clear();
for(int i=0; i<num; i++) {
DataRow *newRow = table->NewRow();
newRow->BeginEdit(); // is this mandatory?
newRow->Item[S"Column1"] = <something>;
newRow->Item[S"Column2"] = <something>;
newRow->EndEdit();
table->Rows->Add(newRow);
}
table->AcceptChanges(); // if not called, I get a oleDbDataAdapter Exception afterwards
}
// then I call UpdateTable(myDataSet, S"myTable");
void UpdateTable(DataSet* dataSet, String* tableName)
{
this->BindingContext->get_Item(dataSet, tableName)->EndCurrentEdit();
oleDbDataAdapter1->Update(dataSet, tableName); // if DataGrid has been edited, then I get DBConcurrencyException
if(dataSet->HasChanges(DataRowState::Added)) { // apparently, returns always FALSE
dataSet->AcceptChanges();
}
}