W
WenYuan Wang [MSFT]
Hello Manjree,
Yes, this is nessary. Because DataSet.Reset method not only clears all the
rows in each table, but also deletes each table in current dataset. It is
necessary for us to set up the schema again for your new dataset (primary
keys and relationships).
By the way, for your informatioin, there is anyother approach by using
TableMappings.
TableMappings could specify which table DBDataAdatper will fill in. We
could define which table in dataset we want to fill data in. Therefor, we
doesn't delete all datatables, but fill the new datas in related table.
Look at the following code snippet.
String^ allSuppliers = L"SELECT * FROM Supplier";
String^ allSamples = L"SELECT * FROM Sample";
String^ select = String::Format(L"{0};{1}",allSuppliers,allSamples);
commandBuilder = gcnew SqlCommandBuilder(adapter);
dataset = gcnew DataSet();
adapter = gcnew SqlDataAdapter(select,conn);
adapter->Fill(dataset);
DataTableCollection^ tables = dataset->Tables;
tables->default[0]->TableName = L"AllSuppliers";
tables->default[1]->TableName = L"AllSamples";
*adapter->TableMappings->Add("Table"," AllSuppliers");
//this line of code means the first table(supplier) need to fill in the
table named ALLsuppliers.
*adapter->TableMappings->Add("Table1"," AllSamples");
//this line of code means the second table(Samples) need to fill the table
named ALLSamples.
*dataset->Clear();
//This time, we need clear the dataset rather than reset all tables. This
means we still reserve the primary key in current tables. Thus we need not
set up schema again.
adapter->Fill(dataset);
DataTableCollection^ tables = dataset->Tables;
nRows = tables->default[L"AllSamples"]->Rows->Count;
str.Format("Records = %d ", nRows);
AfxMessageBox(str);
Hope this helps. Let me know if you have anything unclear. We are glad to
assist.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Yes, this is nessary. Because DataSet.Reset method not only clears all the
rows in each table, but also deletes each table in current dataset. It is
necessary for us to set up the schema again for your new dataset (primary
keys and relationships).
By the way, for your informatioin, there is anyother approach by using
TableMappings.
TableMappings could specify which table DBDataAdatper will fill in. We
could define which table in dataset we want to fill data in. Therefor, we
doesn't delete all datatables, but fill the new datas in related table.
Look at the following code snippet.
String^ allSuppliers = L"SELECT * FROM Supplier";
String^ allSamples = L"SELECT * FROM Sample";
String^ select = String::Format(L"{0};{1}",allSuppliers,allSamples);
commandBuilder = gcnew SqlCommandBuilder(adapter);
dataset = gcnew DataSet();
adapter = gcnew SqlDataAdapter(select,conn);
adapter->Fill(dataset);
DataTableCollection^ tables = dataset->Tables;
tables->default[0]->TableName = L"AllSuppliers";
tables->default[1]->TableName = L"AllSamples";
*adapter->TableMappings->Add("Table"," AllSuppliers");
//this line of code means the first table(supplier) need to fill in the
table named ALLsuppliers.
*adapter->TableMappings->Add("Table1"," AllSamples");
//this line of code means the second table(Samples) need to fill the table
named ALLSamples.
*dataset->Clear();
//This time, we need clear the dataset rather than reset all tables. This
means we still reserve the primary key in current tables. Thus we need not
set up schema again.
adapter->Fill(dataset);
DataTableCollection^ tables = dataset->Tables;
nRows = tables->default[L"AllSamples"]->Rows->Count;
str.Format("Records = %d ", nRows);
AfxMessageBox(str);
Hope this helps. Let me know if you have anything unclear. We are glad to
assist.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.