paulthepaddy
Well-known member
Hi all,
I am getting this error when trying to enter code into my database.
The specified object must not be an instance of a generic type.
Parameter name: obj
This happens when trying to ExecuteNonQuery(Line marked in red below)
i really can't figure out what has happened here as i was using diffrent code a while ago then changed it as their was a few unneeded items in their (data set, data adapter, data rows)
but i am sure this code was working a while ago, and can't figure out the changes. I have included everything that is involved with this.
Sub being called producing the error
The Car class incase it is something to do with the propertys (idk) i coloured the class to try and help make it easier to read. i hope it helps
And here is the database i am trying to enter it into
Cars
I am getting this error when trying to enter code into my database.
The specified object must not be an instance of a generic type.
Parameter name: obj
This happens when trying to ExecuteNonQuery(Line marked in red below)
i really can't figure out what has happened here as i was using diffrent code a while ago then changed it as their was a few unneeded items in their (data set, data adapter, data rows)
but i am sure this code was working a while ago, and can't figure out the changes. I have included everything that is involved with this.
Sub being called producing the error
VB.NET:
Public Sub SaveCarToDB(Car As car, Optional ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Resources\DB.accdb")
Dim con As New OleDb.OleDbConnection
con.ConnectionString = ConnectionString
Dim INSERT As String = "INSERT INTO Cars (Ref_Name, RefTo, Reg, Make, Model, Colour, Price, Paid, OrderNum, KeyNumber, Customer ID, Dates, Invoice Number, Notes) " & _
"VALUES (@Ref_Name, @Reg, @RefTo, @Make, @Model, @Colour, @Paid, @KeyNumber, @Price, @Customer ID, @Dates, @Invoice Number, @OrderNum, @Notes)"
Dim myCommand As New OleDb.OleDbCommand(INSERT)
myCommand.Connection = con
With myCommand.Parameters
'CarID Is The Primary Key & AutoNumber Format
.AddWithValue("@Ref_Name", Car.RefName)
.AddWithValue("@Reg", Car.Reg)
.AddWithValue("@RefTo", Car.RefTo)
.AddWithValue("@Make", Car.Make)
.AddWithValue("@Model", Car.Model)
.AddWithValue("@Colour", Car.Colour)
.AddWithValue("@Paid", Car.Paid)
.AddWithValue("@KeyNumber", Car.KeyNumber)
.AddWithValue("@Price", Car.Price)
.AddWithValue("@Customer ID", Car.CustomerID)
.AddWithValue("@Dates", Car.DateDone.Date)
.AddWithValue("@Invoice Number", Car.Invoices)
.AddWithValue("@OrderNum", Car.OrderNum)
.AddWithValue("@Notes", Car.Notes)
End With
myCommand.Connection.Open()
[COLOR=#ff0000]myCommand.ExecuteNonQuery()[/COLOR]
myCommand.Connection.Close()
The Car class incase it is something to do with the propertys (idk) i coloured the class to try and help make it easier to read. i hope it helps
VB.NET:
Public Class car
'DB Details
[COLOR=#0000ff]Private [/COLOR]_CarID [COLOR=#0000ff]As Integer[/COLOR]
[COLOR=#0000ff]Private [/COLOR] _RefName [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Private [/COLOR] _RefTo [COLOR=#0000ff]As String[/COLOR]
'Car Details
[COLOR=#0000ff]Private [/COLOR] _Reg [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Private [/COLOR] _Make [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Private [/COLOR]_Model [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Private [/COLOR]_Colour [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Private [/COLOR]_Price [COLOR=#0000ff]As Integer[/COLOR]
[COLOR=#0000ff]Private [/COLOR] _Paid [COLOR=#0000ff]As Boolean[/COLOR] = False
[COLOR=#0000ff]Private [/COLOR]_KeyNumber [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Private [/COLOR]_OrderNum [COLOR=#0000ff]As New [/COLOR] List([COLOR=#0000ff]Of Strin g[/COLOR] )
[COLOR=#0000ff]Private [/COLOR]_Notes [COLOR=#0000ff]As New [/COLOR]List([COLOR=#0000ff]Of St ring[/COLOR] )
[COLOR=#0000ff]Private [/COLOR]_Damagelist [COLOR=#0000ff]As New[/COLOR] List ([COLOR=#0000ff]Of String[/COLOR])
[COLOR=#0000ff]Private [/COLOR]_DateDone [COLOR=#0000ff]As Date[/COLOR]
[COLOR=#0000ff]Private [/COLOR]_Invoices [COLOR=#0000ff]As New[/COLOR] List([COLOR=#0000ff]Of Strin g[/COLOR])
[COLOR=#0000ff]Private [/COLOR]_CustomerID [COLOR=#0000ff]As Byte[/COLOR]
'DB Details
[COLOR=#0000ff] Public Property[/COLOR] CarID [COLOR=#0000ff]As Integer[/COLOR]
[COLOR=#0000ff] Get[/COLOR]
[COLOR=#0000ff]Return[/COLOR] _CarID
[COLOR=#0000ff]End Get[/COLOR]
[COLOR=#0000ff]Set[/COLOR](value [COLOR=#0000ff]As Integer[/COLOR])
_CarID = value
[COLOR=#0000ff] End Set
End Property[/COLOR]
[COLOR=#0000ff] Public Property[/COLOR] RefName [COLOR=#0000ff]As String[/COLOR] 'Car Reference Name For Any More Info
[COLOR=#0000ff]Get[/COLOR]
[COLOR=#0000ff]Return [/COLOR]_RefName
[COLOR=#0000ff]End Get[/COLOR]
[COLOR=#0000ff]Set[/COLOR] (value [COLOR=#0000ff]As String[/COLOR])
_RefName = value
[COLOR=#0000ff]End Set[/COLOR]
[COLOR=#0000ff] End Property
Public Property[/COLOR] RefTo [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Get[/COLOR]
[COLOR=#0000ff]Return [/COLOR]_RefTo
[COLOR=#0000ff]End Get[/COLOR]
[COLOR=#0000ff]Set[/COLOR] (value [COLOR=#0000ff]As String[/COLOR])
_RefTo = value
[COLOR=#0000ff] End Set
End Property[/COLOR]
'Car Details
[COLOR=#0000ff] Public Property[/COLOR] Reg [COLOR=#0000ff]As Strin g[/COLOR] ' Car Reg
[COLOR=#0000ff]Get[/COLOR]
[COLOR=#0000ff]Return [/COLOR]_Reg
[COLOR=#0000ff] End Get
Set[/COLOR](value [COLOR=#0000ff]As String[/COLOR])
_Reg = StrConv(value, VbStrConv.Uppercase)
[COLOR=#0000ff] End Set
End Property
Public Property[/COLOR] Make [COLOR=#0000ff]As String[/COLOR] ' Car Make
[COLOR=#0000ff] Get
Return [/COLOR]_Make
[COLOR=#0000ff] End Get
Set[/COLOR](value [COLOR=#0000ff]As String[/COLOR])
_Make = StrConv(value, VbStrConv.ProperCase)
[COLOR=#0000ff] End Set
End Property
Public Property[/COLOR] Model [COLOR=#0000ff]As String[/COLOR] ' Car Model
[COLOR=#0000ff] Get
Return[/COLOR] _Model
[COLOR=#0000ff] End Get
Set[/COLOR](value [COLOR=#0000ff]As String[/COLOR])
_Model = StrConv(value, VbStrConv.ProperCase)
[COLOR=#0000ff] End Set
End Property
Public Property[/COLOR] Colour [COLOR=#0000ff]As String[/COLOR] ' Car Colour
[COLOR=#0000ff] Get
Return[/COLOR] _Colour
[COLOR=#0000ff]End Get
Set[/COLOR](value [COLOR=#0000ff]As String[/COLOR])
_Colour = StrConv(value, VbStrConv.ProperCase)
[COLOR=#0000ff] End Set
End Property
Public Property[/COLOR] Price [COLOR=#0000ff]As Integer[/COLOR]
[COLOR=#0000ff]Get
Return[/COLOR] _Price
[COLOR=#0000ff]End Get
Set[/COLOR](value [COLOR=#0000ff]As Integer[/COLOR])
_Price = value
[COLOR=#0000ff]End Set
End Property
Public Property[/COLOR] Paid [COLOR=#0000ff]As Boolean[/COLOR]
[COLOR=#0000ff] Get
Return[/COLOR] _Paid
[COLOR=#0000ff]End Get
Set([/COLOR]value [COLOR=#0000ff]As Boolean)
[/COLOR]_Paid = value
[COLOR=#0000ff] End Set
End Property
Public Property[/COLOR] KeyNumber [COLOR=#0000ff]As String
Get[/COLOR]
[COLOR=#0000ff]Return [/COLOR]_KeyNumber
[COLOR=#0000ff]End Get
Set[/COLOR](value [COLOR=#0000ff]As String[/COLOR])
_KeyNumber = StrConv(value, VbStrConv.Uppercase)
[COLOR=#0000ff] End Set
End Property
Public Property [/COLOR]OrderNum As List(Of String)
[COLOR=#0000ff] Get
Return[/COLOR] _OrderNum
[COLOR=#0000ff]End Get
Set[/COLOR](value [COLOR=#0000ff]As[/COLOR] List([COLOR=#0000ff]Of String[/COLOR]))
[COLOR=#0000ff] For Each[/COLOR] item [COLOR=#0000ff]In[/COLOR] value
_OrderNum.Add(item)
[COLOR=#0000ff]Next[/COLOR]
[COLOR=#0000ff]End Set
End Property
Public Property[/COLOR] Notes [COLOR=#0000ff]As[/COLOR] List([COLOR=#0000ff]Of String[/COLOR])
[COLOR=#0000ff] Get
Return[/COLOR] _Notes
[COLOR=#0000ff]End Get
Set[/COLOR](value [COLOR=#0000ff]As[/COLOR] List([COLOR=#0000ff]Of String[/COLOR]))
[COLOR=#0000ff] For Each[/COLOR] item [COLOR=#0000ff]In[/COLOR] value
_Notes.Add(item)
[COLOR=#0000ff]Next
End Set
End Property
Public Property[/COLOR] Damagelist [COLOR=#0000ff]As[/COLOR] List([COLOR=#0000ff]Of String[/COLOR])
[COLOR=#0000ff] Get
Return[/COLOR] _Damagelist
[COLOR=#0000ff]End Get
Set[/COLOR](value [COLOR=#0000ff]As[/COLOR] List([COLOR=#0000ff]Of String[/COLOR]))
[COLOR=#0000ff]For Each[/COLOR] item [COLOR=#0000ff]In[/COLOR] value
_Damagelist.Add(item)
[COLOR=#0000ff] Next
End Set
End Property
Public Property[/COLOR] DateDone [COLOR=#0000ff]As Date
Get
Return[/COLOR] _DateDone
[COLOR=#0000ff] End Get
Set[/COLOR](value [COLOR=#0000ff]As Date[/COLOR])
_DateDone = CDate(Format(value, "dd/MM/yyyy"))
[COLOR=#0000ff]End Set
End Property
Public Property[/COLOR] Invoices [COLOR=#0000ff]As [/COLOR]List([COLOR=#0000ff]Of String[/COLOR])
[COLOR=#0000ff]Get[/COLOR]
[COLOR=#0000ff]Return [/COLOR]_Invoices
[COLOR=#0000ff] End Get
Set[/COLOR](value [COLOR=#0000ff]As [/COLOR]List([COLOR=#0000ff]Of String[/COLOR]))
[COLOR=#0000ff] For Each[/COLOR] item [COLOR=#0000ff]In[/COLOR] value
_Invoices.Add(item)
[COLOR=#0000ff] Next
End Set
End Property
Public Property[/COLOR] CustomerID [COLOR=#0000ff]As Byte
Get
Return[/COLOR] _CustomerID
[COLOR=#0000ff] End Get
Set[/COLOR](value [COLOR=#0000ff]As Byte)[/COLOR]
_CustomerID = value
[COLOR=#0000ff] End Set
End Property
[/COLOR]
End Class
And here is the database i am trying to enter it into
CarID | Ref_Name | RefTo | Reg | Make | Model | Colour | Price | Paid | OrderNum | WorkDone | Dates | Invoice Number | Customer ID | KeyNumber |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | ULZ 8989 | ULZ 8989 | Ford | Focus | Red | 100 | No | 21/05/2012 | LFC2012p1 | 4 | ||||
2 | ULZ 1111 | ULZ 1111 | Ford | Focus | Yellow | 100 | No | 21/05/2012 | VWB2012W | 4 | ||||
3 | ULZ 1113 | David Morison | ULZ 1113 | VW | Golf | Silver | 100 | No | 21/05/2012 | VWB2012P | 1 | |||
4 | ULZ 1112 | ULZ 1112 | VW | Polo | Red | 25 | No | 21/05/2012 | VWB2012W | 1 | ||||
5 | ULZ 1114 | ULZ 1114 | VW | Golf | White | 75 | No | 21/05/2012 | VWB2012P | 1 | ||||
6 | ULZ 1115 | ULZ 1115 | toyota | nissan | Pink | 85 | No | 21/05/2012 | VWB2012P | 1 | ||||
7 | ULZ 1119 | ULZ 1119 | VW | Polo | White | 150 | No | 21/04/2012 |