|
-
July 11th, 2012, 02:41 AM
#1
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 ( cod, den, abr, data, telegrama)"
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?
-
July 11th, 2012, 08:49 AM
#2
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
Always use [code][/code] tags when posting code.
-
July 12th, 2012, 01:57 AM
#3
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?
-
July 12th, 2012, 08:40 AM
#4
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?
-
July 12th, 2012, 11:15 AM
#5
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)
-
July 12th, 2012, 11:17 PM
#6
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).
-
July 13th, 2012, 01:42 PM
#7
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)
-
July 13th, 2012, 01:53 PM
#8
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 & ")"
Last edited by d.paulson; July 13th, 2012 at 01:55 PM.
-
July 16th, 2012, 01:47 AM
#9
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 telegrama. So, many thanks for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|