|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Object must be IConvertible
hi, can anyone please help i've got this set of code that everytime i run i get this error and i dont know what the problem is.<br>the code is:<br><br>Sub doInsert(Source as Object, E as EventArgs)<br> Dim myConnectionString as string ="Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:Inetpubwwwrootdelete asset inwinfix.mdb;"<br> Dim myInsertQuery as string = "Insert into Asset(***_Code, ***_Description, ***_Type, ***_Disposal_Date, " & _<br> "***_Supplier, ***_Serial_Number, ***_Manufacturer, ***_Part_Number, ***_Acquired_Date, ***_Commissioned_Date," & _<br> "***_Original_Cost, ***_Scrap_Value, ***_Notes, ***_Status) " & _<br> "values(?,?,?,?,?,?,?,?,?,?,?,?)"<br>Dim myConnection As New OleDbConnection(myConnectionString)<br> Dim myCommand As New OleDbCommand(myInsertQuery, myConnection)<br> Dim DS As DataSet<br> <br> myCommand.Parameters.Add(New OLEDBParameter("@***_Code", OLEDBType.Char, "20")).Value = ***_Code<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Description", OLEDBType.Char, "50")).Value = ***_Description<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Type", OLEDBType.Char, "2")).Value = ***_Type<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Disposal_Date", OLEDBType.DBDate, "20")).Value = Today.Month & "/" & Today.Day & "/" & Today.Year<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Supplier", OLEDBType.Char, "20")).Value = ***_Supplier<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Serial_number", OLEDBType.Integer)).Value = ***_Serial_Number<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Manufacturer", OLEDBType.Char, "20")).Value = ***_Manufacturer<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Part_number", OLEDBType.Integer)).Value = ***_Part_Number<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Acquired_Date", OLEDBType.DBDate, "20")).Value = Today.Month & "/" & Today.Day & "/" & Today.Year<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Commissioned_Date", OLEDBType.DBDate, "20")).Value = Today.Month & "/" & Today.Day & "/" & Today.Year<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Original_Cost", OLEDBType.Currency)).Value = ***_Original_Cost<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Scrap_Value", OLEDBType.Currency)).Value = ***_Scrap_Value<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Notes", OLEDBType.Char, "100")).Value = ***_Notes<br> myCommand.Parameters.Add(New OLEDBParameter("@***_Status", OLEDBType.Char, "20")).Value = ***_Status<br><br> myCommand.Connection.Open()<br> myCommand.ExecuteNonQuery()<br> MyConnection.Close() <br> <br>End Sub<br><br>i'll be waiting for your suggestions <br>thx
|
|
#2
|
|||
|
|||
|
Did you just shorten the code with the ?,?,? part of the SQL?<br><br>If not, then try putting the @***_... parameter name in the correct place.<p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>
|
|
#3
|
|||
|
|||
|
Also, instead of using<br><br>myCommand.Parameters.Add(New OLEDBParameter("@***_Code", OLEDBType.Char, "20")).Value = ***_Code<br><br>Try (of course, only dim once)<br><br>Dim myParam as OLEDBParameter = myCommand.Parameters.Add("@***_Code", OLEDBType.Char, "20")<br>myParam.Value = ***_Code<p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>
|
|
#4
|
|||
|
|||
|
i've tried all ur saying but still getting the same error <img border="0" src="/forum/emoticons/confused.gif" height="22" width="15" alt="confused" />
|
|
#5
|
|||
|
|||
|
What line is it erroring on?<p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>
|
|
#6
|
|||
|
|||
|
Oh, one thing I just noticed...<br><br>When passing to non-string values, you must convert the value to the data type being passed. For example<br><br>DBDate : CDate(value)<br>Int : CInt(value)<br>Money : CDbl(value)<p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > Object must be IConvertible |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|