Question Problem with saving data in table

victor64

Well-known member
Joined
Nov 9, 2008
Messages
60
Programming Experience
Beginner
Hello,

I am trying to update a link table with values from multiple datagrids, the field types in the link table are numbers and the value selected from the datagrids are also numbers.

I am getting the following error:

The OleDbParameterCollection only accepts non-null OleDbParameter type objects, not String objects.

In line : cmdCompany.Parameters.Add("@COMPANY_ID")


Any ideas on how to fix this error?

Thanks in advance

Victor

Code:

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\aop29.mdb"

Dim cmdCompany As OleDbCommand
Dim cmdReceiver As OleDbCommand

Dim CompanySQL As String
Dim ReceiverSQL As String

Dim objConnection As New OleDb.OleDbConnection(ConnectionString)

Dim Trans As OleDbTransaction

CompanySQL = "INSERT INTO Link_TableA(CALIBER_ID) VALUES(@Company_ID)"

cmdCompany = New OleDbCommand(CompanySQL, objConnection)

cmdCompany.Parameters.Add("@Company_ID") *****ERROR LOCATION

cmdCompany.Parameters("@Company_ID").Value = C1TrueDBGrid1.Columns(0).Value



ReceiverSQL = "INSERT INTO Link_TableA(Receiver_ID) VALUES(@Receiver_ID)"

cmdReceiver = New OleDbCommand(ReceiverSQL, objConnection)

cmdReceiver.Parameters.Add("@Receiver_ID")

cmdReceiver.Parameters("@Receiver_ID").Value = C1TrueDBGrid2.Columns(0).Value


Try
Trans = objConnection.BeginTransaction

cmdCompany.Transaction = Trans

cmdCompany.ExecuteNonQuery()

cmdReceiver.Transaction = Trans

cmdReceiver.ExecuteNonQuery()

Trans.Commit()

Catch ex As Exception
an error occurred, so rollback the transaction
If Not Trans Is Nothing Then
Trans.Rollback()
End If

MsgBox("Error saving data.")
MsgBox(ex.Message)

End Try
 
Hello,

I got it to work partially with the code below, the problem is the data from each grid is saved in different records, is there a way to save the data from both grids in one record?. I don't don't know how to concatenate the code, perhaps that would be the solution.

Thanks,

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\aop29.mdb"
Dim cmdCompany As OleDbCommand
Dim cmdReceiver As OleDbCommand

Dim CompanySQL As String
Dim ReceiverSQL As String

Dim objConnection As New OleDb.OleDbConnection(ConnectionString)
objConnection.Open()
Dim Trans As OleDbTransaction

CompanySQL = "INSERT INTO Link_TableA(Company_ID) VALUES(@Company_ID)"

cmdCompany = New OleDbCommand(CompanySQL, objConnection)

cmdCompany.Parameters.AddWithValue("@Company_ID", C1TrueDBGrid1.Columns(0).Value)

ReceiverSQL = "INSERT INTO Link_TableA(Receiver_ID) VALUES(@Receiver_ID)"
cmdReceiver = New OleDbCommand(ReceiverSQL, objConnection)

cmdReceiver.Parameters.AddWithValue("@Receiver_ID", C1TrueDBGrid2.Columns(0).Value)

Try
Trans = objConnection.BeginTransaction

cmdCompany.Transaction = Trans

cmdCompany.ExecuteNonQuery()

cmdReceiver.Transaction = Trans

cmdReceiver.ExecuteNonQuery()

Trans.Commit()

Catch ex As Exception
'an error occurred, so rollback the transaction
If Not Trans Is Nothing Then
Trans.Rollback()
End If

MsgBox("Error saving data.")
MsgBox(ex.Message)
 
Back
Top