davymartu
davymartu

Reputation: 1443

ADODB.Recordset addnew with an Oracle package field

Hy guys. I have a visual basic 6 program with an Oracle DB. When i add a record to table i do:

Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Title") = "Titolo"
Adodc1.Recordset.Fields("Author") = "Autore"
Adodc1.Recordset.Fields("IP") = "10.0.1.1"
Adodc1.Recordset.Update

This routine is ok, but i want to set IP with an oracle function: sys_context('USERENV','IP_ADDRESS')

When i have modified my routine in

Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Title") = "Titolo"
Adodc1.Recordset.Fields("Author") = "Autore"
Adodc1.Recordset.Fields("IP") = "sys_context('USERENV','IP_ADDRESS')"
Adodc1.Recordset.Update

the field of table is always null. There are workaround for this problem? Thanks in advance

Upvotes: 0

Views: 369

Answers (1)

Rob
Rob

Reputation: 3381

I think the simple answer is you cannot do it that way. As it is written you are assigning the fixed string 'sys_context('USERENV','IP_ADDRESS')' into the 'IP' field.

To use that function you will have to construct an INSERT statement and execute it directly. Somethink like

INSERT INTO your_table ( Title, Author, IP ) SELECT 'Titolo', 'Autore', sys_context('USERENV','IP_ADDRESS')

Alternatively you could create a stored procedure and execute that (which might be better in the long run)

Upvotes: 1

Related Questions