This is in VB. I have a text box where I get the user to enter a SQL statement. I would then like to execute this and display the results in another text box.
.connectionstring = "the connection string for your database"
.open
end with
'Check if the connection opened correctly
if oConnection.state = adstateopen then
bConnected = true
else
bconnected = false
end if
getconnection = bconnected
end function
'This is the part that does the work
Private sub ExecuteSQL()
dim oRs as adodb.recordset
'Establish your connection and test it
if getconnection = true then
'Create the recordset
set oRs new adodb.recordset
'The executes the SQL against the connection and populates the recordset
with oRS
.activeconnection = oconnection
.source = text1.text 'The SQL source textbox
.open
end with
'populate the other textbox
'This will loop until the end of the recordset
while not oRS.eof
text2.text = oRS.fields("Field_Name".value
wend
I hope this gives you a good starting point if you need more info then leave a comment
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.