How can I write to an external table within a breakout?

Discussions relating to breakout scripting, .NET and COM programming with Jiwa objects.

How can I write to an external table within a breakout?

Postby indikad » Mon Jun 29, 2009 1:05 pm

I want to write to an external ( user created table - within the JIWA company databse)

my code below did not work.

any hints ? Thanks very much.

Code: Select all
With SalesQuoteObject.Database
        rHwnd = .StatementOpen(.ConnectionWrite, , , 0)
        sqlInsert = "INSERT INTO  key_QO_LineCustomValues (InvoiceHistoryID) "
        sqlInsert = sqlInsert & " 'ABCD1234' "

        If .ExecuteSQL(CInt(rHwnd), sqlInsert) Then
            MsgBox "good"
        End If
        .StatementClose CInt(rHwnd)

    End With


then I tried to use teh folowing and it gives me an overflow error - I suspect the sql user does not let me do inserts, sice if I replace this users with sa it worked.

Code: Select all
sqlInsert = "INSERT INTO  MyTable (InvoiceHistoryID) "
    sqlInsert = sqlInsert & " VALUES ('ABCD1234') "
    With SalesQuoteObject.Database
       MsgBox "server = " &  .ServerName & " db = " &  .DatabaseName
        sCon = "Driver={SQL Server};Server=" & .ServerName & ";Database=" & .DatabaseName & ";UID=" & .SQLLoginName & ";PWD=" & .SQLLoginPassword
        MsgBox sCon
        cn.Open sCon
        cn.Execute sqlInsert
    End With
Set cn = nothing
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I write to an external table within a breakout?

Postby Mike.Sheen » Tue Jun 30, 2009 12:55 pm

Indika,

Your first snippet does not commit the transaction. I assume when you say it did not work, it did not return any errors, but the row was not written to the table ?

Try this (I just added the .Commit, error handling, and the VALUES clause)

Code: Select all
With SalesQuoteObject.Database
        rHwnd = .StatementOpen(.ConnectionWrite, , , 0)
        sqlInsert = "INSERT INTO  key_QO_LineCustomValues (InvoiceHistoryID) "
        sqlInsert = sqlInsert & " VALUES ('ABCD1234') "

        If .ExecuteSQL(CInt(rHwnd), sqlInsert) Then
            MsgBox "good"
        Else
            MsgBox "Error : " & .ErrorMessage
        End If

        .Commit

        .StatementClose CInt(rHwnd)

    End With


then I tried to use teh folowing and it gives me an overflow error - I suspect the sql user does not let me do inserts, sice if I replace this users with sa it worked.

Code: Select all
sqlInsert = "INSERT INTO  MyTable (InvoiceHistoryID) "
    sqlInsert = sqlInsert & " VALUES ('ABCD1234') "
    With SalesQuoteObject.Database
       MsgBox "server = " &  .ServerName & " db = " &  .DatabaseName
        sCon = "Driver={SQL Server};Server=" & .ServerName & ";Database=" & .DatabaseName & ";UID=" & .SQLLoginName & ";PWD=" & .SQLLoginPassword
        MsgBox sCon
        cn.Open sCon
        cn.Execute sqlInsert
    End With
Set cn = nothing



Of course, the SQL User would need permissions to INSERT into the table MyTable - have you set this ?

If you prefer to work with ADO directly, the Jiwa ADO connection can be accessed via the Database.ADOConnectionObject, thus eliminating your need to create a connection yourself.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How can I write to an external table within a breakout?

Postby indikad » Thu Jul 02, 2009 1:33 pm

Thanks Mike. I will try this code.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2

Re: How can I write to an external table within a breakout?

Postby Mike.Sheen » Mon Jul 06, 2009 9:55 pm

indikad wrote:Thanks Mike. I will try this code.


Did that work for you ?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How can I write to an external table within a breakout?

Postby indikad » Tue Jul 21, 2009 3:29 pm

Hi Mike,

The modification I was writing evolved in to something that did not need writing to the table so I did not try this starightaway.

I tried it today and ( as you pointed out) get thrownback because the sql user does not have writing rights to my table. I would rather use the ADOConnection , so that I dont have to worry about setting permissions etc.

Thanks very much for this. you code will anyhow be usefull for writing to Jiwa tables.
indikad
Frequent Contributor
Frequent Contributor
 
Posts: 182
Joined: Thu Jun 18, 2009 1:14 pm
Topics Solved: 2


Return to Technical / Programming

Who is online

Users browsing this forum: No registered users and 5 guests