Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 8th, 2003, 10:42 PM
Authorized User
 
Join Date: Jun 2003
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.

Thanks

Arshad Mahmood

arshad mahmood
__________________
arshad mahmood
 
Old July 9th, 2003, 07:59 AM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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"
   .Open
End With

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

rst.Open strSQL, cxn, adOpenStatic, adLockOptimistic

MyForm.MtTextBox.Text = rst!Title

rst.Close
Set rst = Nothing
cxn.Close
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





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





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