Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 8th, 2003, 10:42 PM
Authorized User
Join Date: Jun 2003
Location: rawalpindi, panjab, Pakistan.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to arshad mahmood
Default How to display query recults in a textbox controle

Hello Sir
I want to know that how to display the guery result in a textbox when
i execute the query by clicking the command button.for example:
if i want to display the title of a specific book in a textbox like

SELECT title from BOOK where book_id=1;
i want to display the result of this query in textbox on form when i execute this query by clicking the button on the form.

I hope u will tell me.


Arshad Mahmood

arshad mahmood
arshad mahmood
Reply With Quote
  #2 (permalink)  
Old July 9th, 2003, 07:59 AM
Authorized User
Join Date: Jun 2003
Location: , FL, USA.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts

This is the method that I use...

Dim cxn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String

Set cxn = New ADODB.Connection
Set rst = New ADODB.Recordset

With cxn
   .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
   "Absolute Path to your DB"
End With

strSQL = _
  "SELECT Title " & _
  "FROM Book " & _
  "WHERE book_id=1;"

rst.Open strSQL, cxn, adOpenStatic, adLockOptimistic

MyForm.MtTextBox.Text = rst!Title

Set rst = Nothing
Set cxn = Nothing

I used 'MyForm.MtTextBox.Text = rst!Title' because I have this code in a seperate module named RecordSets and call it from the Form_Load sub that use it. It is up to you where you put I just prefer my code modules to look cleaner. Be sure to included references to Microsoft ActiveX Data Objects 2.5 Library (or Later) and Microsoft Data Binding Collection VB 6.0 SP4 (or later.

Hope this helps......

Kenny Alligood
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get and display a data in textbox kakac ASP.NET 2.0 Basics 1 April 20th, 2007 08:12 AM
how to display value to textbox tllcll Javascript 1 October 27th, 2005 09:10 AM
display the result of query in textbox. Abhinav_jain_mca ADO.NET 4 August 3rd, 2004 03:34 AM
How to search and display in textbox a specific .. arshad mahmood VB Databases Basics 1 July 11th, 2003 08:07 AM
How to display dataset using textbox RockNRoll ASP.NET 1.0 and 1.1 Basics 1 July 4th, 2003 07:37 AM

All times are GMT -4. The time now is 07:17 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.