CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2009
    Posts
    40

    Unhappy 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?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    40

    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?

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    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?

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Nov 2009
    Posts
    40

    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).

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    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)

  8. #8
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    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.

  9. #9
    Join Date
    Nov 2009
    Posts
    40

    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
  •  





Click Here to Expand Forum to Full Width

Featured