emaduddeen
Well-known member
- Joined
- May 5, 2010
- Messages
- 171
- Location
- Lowell, MA & Occasionally Indonesia
- Programming Experience
- Beginner
Getting "OleDbCommand.Prepare method requires all parameters to have an explicitly...
Hi Everyone,
I am using dataset to update/insert the data in the database. Whenever its about to update the dataset, it gives me the following error:
"OleDbCommand.Prepare method requires all parameters to have an explicitly set type."
Can somebody please help me with this problem because using this code in SQL Server works but not in MS Access?
If you know if a better way to get the data into the dataset and into the database, please show me the better way.
Here is my code. Hope you don't mind a lot of code in here:
Thanks in advance.
Truly,
Emad
Hi Everyone,
I am using dataset to update/insert the data in the database. Whenever its about to update the dataset, it gives me the following error:
"OleDbCommand.Prepare method requires all parameters to have an explicitly set type."
Can somebody please help me with this problem because using this code in SQL Server works but not in MS Access?
If you know if a better way to get the data into the dataset and into the database, please show me the better way.
Here is my code. Hope you don't mind a lot of code in here:
VB.NET:
Public Sub SaveToDatabase()
' Set up a new blank data row if the user chose to Insert.
'---------------------------------------------------------
If booleanAddNew Then
objDataAdapterCustomerDetails.SelectCommand.Parameters("CustomerID") _
.Value = 0
objDataAdapterCustomerDetails.Fill(objDataSetCustomerDetails, _
"Customer Details")
objDataRowCustomerDetails = objDataSetCustomerDetails _
.Tables("Customer Details").NewRow()
End If
' Start the editing in the datarow.
'----------------------------------
objDataRowCustomerDetails.BeginEdit()
' Loop through each of the controls in the General Customer Details tab.
'-----------------------------------------------------------------------
For Each objSingleControl In TabPageGeneral.Controls
If TypeOf objSingleControl Is EditBox Then
' Each text box control starts with "EditBox" followed by the column name.
' This line will get the column name from the text box so data can be taken
' from the data row.
'--------------------------------------------------------------------------
strControlName = Mid(objSingleControl.Name, 8)
Try
' Grab a textbox's data and place it into a DataRow column.
'----------------------------------------------------------
objDataRowCustomerDetails(strControlName) = objSingleControl.text
Catch exException As Exception
MessageBox.Show("Data row column not the same as control name: " & _
objSingleControl.Name)
End Try
End If
Next
' Finish the editing of the data row.
'------------------------------------
objDataRowCustomerDetails.EndEdit()
Try
' Add a new blank row into the Data Set if the user chose to Insert.
'-------------------------------------------------------------------
If booleanAddNew Then
objDataSetCustomerDetails.Tables("Customer Details") _
.Rows.Add(objDataRowCustomerDetails)
End If
' Create an instance of the command builder.
'-------------------------------------------
objCommandBuilderParentDetails = _
New OleDbCommandBuilder(objDataAdapterCustomerDetails)
If booleanAddNew Then
' Have the command builder create an Insert SQL command.
'-------------------------------------------------------
objDataAdapterCustomerDetails.InsertCommand = _
objCommandBuilderParentDetails.GetInsertCommand
Else
' Have the command builder create an update SQL command.
'-------------------------------------------------------
objDataAdapterCustomerDetails.UpdateCommand = _
objCommandBuilderParentDetails.GetUpdateCommand
End If
' Perform the update SQL command; then close the connection.
'-----------------------------------------------------------
objDataAdapterCustomerDetails _
.Update(objDataSetCustomerDetails, "Customer Details")
If booleanAddNew Then
' Close the connection opened by the insert command.
'---------------------------------------------------
objDataAdapterCustomerDetails.InsertCommand.Connection.Close()
' Re-load the Datset View because there is a new row of data.
'------------------------------------------------------------
PopulateDataGridWithCustomerNames()
Else
' Close the connection opened by the update command.
'---------------------------------------------------
objDataAdapterCustomerDetails.UpdateCommand.Connection.Close()
End If
LightGridCustomerNames.Focus()
' Reset this since it's not needed now.
'--------------------------------------
booleanAddNew = False
Catch saveException As Exception
Throw saveException ' to whoever called this sub routine.
End Try
End Sub
Thanks in advance.
Truly,
Emad