By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

C++/CLI OleDbException Error

100+
P: 255
Hi guys,

I'm having a System.Data.OleDb.OleDbException error with C++/CLI language environment. I've created a form with a DataGridView to show the whole table from the database, it is allowed to modify the records from the DataGridView. Once a button is pressed it will start the code below
Expand|Select|Wrap|Line Numbers
  1. conn->Open();
  2.  
  3. //Get changed rows if existed
  4. dsChange = dsFac->GetChanges(DataRowState::Modified);
  5. dsAdd = dsFac->GetChanges(DataRowState::Added);
  6. dsDelete = dsFac->GetChanges(DataRowState::Deleted);
  7.  
  8. da = daFac;
  9. strTable = "Facility";
  10.  
  11. if(dsChange)
  12. {
  13.     strSQL = "UPDATE Facility "
  14.              "SET FName = @FName, FDescription = @FDescription "
  15.              "WHERE FID = @FID";
  16.     cmd = gcnew OleDbCommand(strSQL,conn);
  17.     cmd->Parameters->Add("@FID", OleDbType::Char, 5, "FID");
  18.     cmd->Parameters->Add("@FName", OleDbType::VarChar, 15, "FName");
  19.     cmd->Parameters->Add("@FDescription", OleDbType::VarChar, 40, "FDescription");
  20.     da->UpdateCommand = cmd;
  21.     da->Update(dsChange, strTable);
  22. }
  23. if(dsAdd)
  24. {
  25.     strSQL = "INSERT INTO Facility (FID, FName, FDescription) "
  26.              "VALUES (@FID, @FName, @FDescription)";
  27.     cmd = gcnew OleDbCommand(strSQL,conn);
  28.     cmd->Parameters->Add("@FID", OleDbType::Char, 5, "FID");
  29.     cmd->Parameters->Add("@FName", OleDbType::VarChar, 15, "FName");
  30.     cmd->Parameters->Add("@FDescription", OleDbType::VarChar, 40, "FDescription");
  31.     da->InsertCommand = cmd;
  32.     da->Update(dsAdd, strTable);
  33. }
  34. if(dsDelete)
  35. {
  36.     strSQL = "DELETE FROM Facility WHERE FID = @FID";
  37.     cmd = gcnew OleDbCommand(strSQL,conn);
  38.     cmd->Parameters->Add("@FID", OleDbType::Char, 5, "FID");
  39.     da->DeleteCommand = cmd;
  40.     da->Update(dsDelete, strTable);
  41. }
The code above will detect the Modified, Added, Deleted actions made from the user. For example I'm updating one of the FDescription field in the records, pressed the button and it shows an error pointing to this line.
Expand|Select|Wrap|Line Numbers
  1. da->Update(dsChange, strTable);
Where the error message is:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: No value given for one or more required parameter


This is the stack captured for the error..
Expand|Select|Wrap|Line Numbers
  1.      System.Data.dll!System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(System.Data.Common.RowUpdatedEventArgs rowUpdatedEvent, System.Data.Common.DbDataAdapter.BatchCommandInfo[] batchCommands, int commandCount) + 0x18b bytes    
  2.      System.Data.dll!System.Data.Common.DbDataAdapter.UpdatedRowStatus(System.Data.Common.RowUpdatedEventArgs rowUpdatedEvent, System.Data.Common.DbDataAdapter.BatchCommandInfo[] batchCommands, int commandCount) + 0x2e bytes    
  3.      System.Data.dll!System.Data.Common.DbDataAdapter.Update(System.Data.DataRow[] dataRows, System.Data.Common.DataTableMapping tableMapping) + 0x7d2 bytes    
  4.      System.Data.dll!System.Data.Common.DbDataAdapter.UpdateFromDataTable(System.Data.DataTable dataTable, System.Data.Common.DataTableMapping tableMapping) + 0x2a bytes    
  5.      System.Data.dll!System.Data.Common.DbDataAdapter.Update(System.Data.DataSet dataSet, string srcTable) + 0xb1 bytes    
  6. >    WWZ_Admin.exe!WWZ_Admin::WWZ_DB::btnUpdate_Click(System::Object^ sender, System::EventArgs^ e) Line 372 + 0x11 bytes    C++
  7.  
Can anyone tell me what am I missing on the dataset settings? or is it an error in another part? Any help is greatly appreciated.
Oct 3 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.