|
-
Oct 5th, 2000, 04:04 AM
#1
Thread Starter
Lively Member
Hi
Sorry to bother you all!
I need to write a sql statement to pull records from a database.
I have made the connection with the Data enviroment and populated a datacombo box with the data.
I want to be able to click on a data entry and pull up the fields.
Displaying them in text boxes!
How can this be done?
I know that this is so simple that it is an insult to ask you guys but once I can do this simple thing I am sure that I Can move on to greater things.
Thanks for your help
Simon
-
Oct 5th, 2000, 05:53 AM
#2
Hyperactive Member
When the user selects which record that they wish to see you need to run a SQL statement that selects * from you table where a value = the value that the user has selected this would be most effective if it was a primary key field that they selected. When you pull back the record you can just set each text box to the value of each field. If you have your text boxes set up in an array a handy way to do this would be
for i = 0 to rs.fields.count
txtBox(i) = rs(i)
next
HTH
-
Oct 5th, 2000, 06:01 AM
#3
Thread Starter
Lively Member
I see!
Being as dumb as I am how exactually do I pass that SQL statement
Something like
open database
query database
close database
What is the VB code?
And if the controls are bound to the datafields then chaning one will not nessecarly change the others is that right?
Simon
-
Oct 5th, 2000, 07:36 AM
#4
Hyperactive Member
If it is ADO you are using you will need a command object and a connection
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = 'Your connection object here
cmd.CommandTimeout = 0
cmd.CommandText = 'your sql string here
cmd.Execute
Set cmd = Nothing
-
Oct 5th, 2000, 09:39 AM
#5
Lively Member
From what you said in you first message Simon, it sounds like you already have a DataEnvironment Connection open.
This is the code I use in that case.
Dim strSQL As String
Dim rstTemp As ADODB.Recordset
Dim fld As ADODB.Field
i=0
strSQL = "SELECT Field" _
& " FROM Table"_
& " WHERE Table.Field = '" DataComboBox.Text "';"
' Identifies which ADO connection is being used for SQL.
Set rstTemp = DataEnvironment1.Connection1.Execute(strSQL, , adCmdText)
For Each fld In rstTemp.Fields
txtBox(i+1) = fld.Value
Next
rstTemp.Close
Set rstTemp = Nothing
Hope that helps you...If you haven't got you connection open then you will need DataEnvironment1.Connection1.Open
sort of thing
Cheers
Jonny
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
|