Solved

Notes and SQL

Posted on 1998-10-21
6
204 Views
Last Modified: 2013-12-18
     I need  to build an application to access data from an SQL database. I´ve made an application that makes an SQL query to an SQL database , but the code is entirely in an agent.  And it shows the results in messageboxes.
      I´d like to have a screen with a field where someone can fill with the name to be searched, and this name should be passed to the agent. I´d like to show the results in the format of a table too.
      I was thinking that if I create a field in a form, in order to people type the name to be searched , it would work, but Notes always ask me to save the document, and I don´t want to have one document for each query people make.
      I thought about creating a field in a navigator, so that Notes wouldn´t ask me to save the document. But it doesn´t let me create a field in a navigator.
      How can I make it? How can I pass a parameter filled by an user to an agent ?
      And how can I format the results in a table , using lotus script ?
      Have anybody done an application like this ?

                                    Thanks in advance !
                                    Priscila
0
Comment
Question by:ptenuta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
wrichard earned 50 total points
ID: 1117581
To pass the value of a field to the agent that you wrote you will need to have the triggering action (i.e. push button, field exit) write the value of that field to the Notes.INI file by using the session.setenvironmentstring and then read the value from the agent.  An easier solution would be to move your agent code into a push button that will read the value from the uidoc directly into the script and then execute the query.  As far as writing the results in a table, you will have to parse through the result set in script and populate the different variables using the values from the result set, Chr(10) (new line), and & (concatenate).  Once you have finished populating the variables you can write them back to the form using  the uidoc class.
0
 

Author Comment

by:ptenuta
ID: 1117582
Ok. So let´s concentrate on the easier solution . Here is the code (executed when a user clicks a button) I´ve built until now:

Dim Workspace As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     Dim research As String
     Dim con As New ODBCConnection
     Dim qry As New ODBCQuery
     Dim result As New ODBCResultSet
     Set uidoc = workspace.CurrentDocument
     pesquisa = uidoc.FieldGetText("name")
     If con.ConnectTo("database") Then
          Set qry.Connection = con
          qry.SQL = "SELECT EName FROM Employees where EName LIKE" & "research" - > this doesn´t work . How can I reference to a variable here ?????
         .
         .
         .

0
 
LVL 1

Expert Comment

by:wrichard
ID: 1117583
If research is a value that is going to be taken from the uidoc then refernece it from the uodoc class:
qry.SQL = "SELECT EName FROM Employees where EName LIKE '" & uidoc.FieldGetText("research") & "'".
If it is a variable that has been set inside your script then reference it without quotes:
pesquisa = uidoc.FieldGetText("name")
qry.SQL = "SELECT EName FROM Employees where EName LIKE '" & pesquisa & "'"

If you notice I have appended and prepended single quotes around the variables.  When you reference a string via the sql query you need single quotes around it. If you reference a number you do not need single quotes.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ptenuta
ID: 1117584
I´m still having problems with this part of the problem :
          pesquisa = uidoc.FieldGetText("name")
          qry.SQL = "SELECT EName FROM Employees where EName LIKE '" & pesquisa & "'"

If I put this code :
          qry.SQL = "SELECT EName FROM Employees where EName LIKE 'Priscilla Tenuta'"
it works perfectly.
But when I type the same name in the field, it does not work. It returns "false" . Why is that ?
0
 
LVL 1

Expert Comment

by:wrichard
ID: 1117585
I would run the program through the debug mode (debug lotus script) and view the qry section of variables.  Look at the sql variable in that section and see exactly what is being stored in that variable and what is being passed to the SQL server.
0
 

Expert Comment

by:Shirish
ID: 1117586
Priscilla,
Passing the value  via environment variables would work.
If your variable is of string or variant type, you will have to include single quotes before and after the variable name.
Eg.
qry.SQL = "SELECT * FROM EmpInformation WHERE Location = '" & varname & "'"
One way of debugging SQL statements is to display them using a Message or Input box, just before executing them in Notes and running them in the RDBMS SQL tool separately.
Eg.
teststring = "SELECT * FROM EmpInformation WHERE Location = '" & uidoc.FieldGetText("name") & "'"
MessageBox teststring
qry.SQL = teststring
etc.

Use the methods in ResultSet Class such as GetValue,NextRow, etc to obtain results and format using Chr(10), New line, etc
Hope this helps

0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question