I need help for an insert
Hi,
I'm traying to run a function on server which is supposed to insert a record in a table. I'm having problems with this function
Public Function InsertSirPlj(ByVal xCOD As Decimal, ByVal xDEN As String, ByVal xABR As String, ByVal xSTARE As String, ByVal xDATA As DateTime, ByVal xTLG As String) As Boolean
Dim sqlInsert = "insert into sirplj(COD , DEN , ABR , 'D', DATA , TELEGRAMA ) VALUES (:pcod, :pden,:pabr, :pdata, :ptelegrama)"
On Error GoTo xError
Oraclecon.Open()
Dim cmdInsert = New OracleCommand()
cmdInsert.CommandText = sqlInsert
cmdInsert.Connection = Oraclecon
Dim pCOD = New OracleParameter()
pCOD.DbType = DbType.Double
pCOD.Value = xCOD
pCOD.ParameterName = "pCOD"
..... the other parameters
cmdInsert.Parameters.Add(pCOD)
........
cmdInsert.Parameters.Add(pTLG)
cmdInsert.ExecuteNonQuery()
cmdInsert.Dispose()
.......
It gives me this:
System.InvalidCastException: Conversion from string "ORA-00972: identifier is too lon" to type 'Boolean' is not valid. System.FormatException: Input string was not in a correct format.
I'm new in VB and I really don't know what to do. Can anyone help me?
Re: I need help for an insert
The error is pretty clear you are trying to use a string value for a boolean field which causes an exception.
That error message looks more like what I would expect under VB.Net rather than VB6 though
Re: I need help for an insert
You might be right, but I don't have a boolean in insert statement. The error appear when the function reach the line "cmdInsert.ExecuteNonQuery()". I do have boolean function, but could that generate the error?
Re: I need help for an insert
Just by looking at your statement
Code:
insert into sirplj(COD , DEN , ABR , 'D', DATA , TELEGRAMA ) VALUES (cod, den,abr, data, telegrama)
I find an inconsistence: you specify 6 fields (COD, DEN, ABR, 'D', DATA, TELEGRAMA),
but you only give 5 Values (cod, den, abr, data, tlegrama)
You sure, the 'D' is a valid field specifier in your recordset?
Re: I need help for an insert
If you open the table in Access, and past your insert statement, it will point to the line POSITION of the error. Once you fix all the errors, copy the statement back to VB6 (and format it for VB)
Re: I need help for an insert
The value for D is 'D' and it is written just like that. I will try with Access and then come back (I hope to find the error).
Re: I need help for an insert
I'm not sure if you can just put a value within the field section. Field names and values must match. So I'd expect a command like
Code:
insert into sirplj(COD , DEN , ABR , D, DATA , TELEGRAMA ) VALUES (pcod, pden, pabr, 'D', pdata, ptelegrama)
Re: I need help for an insert
If values are variables your sql should be like
Code:
sqlInsert = "insert into sirplj(COD , DEN , ABR , D, DATA , TELEGRAMA ) VALUES ( " & cod & ", " & den & ",'D', " & abr & ", " & data & ", " & telegrama & ")"
Re: I need help for an insert
Many thanks. I've solved the problem. It was a "sintax" error: the telegrama parameter was added as pTLG instead of :ptelegrama. So, many thanks for your help.