473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Query In Vb

24
I Am Using Vb 6
How To Write A Qury In Vb
And Then How And Where To Call That Query



Let I Write The Following Query
Select Roll No From Std

Now I Want To Display The Result Of Query In A Textbox
How This Will Be Done .and Where I Will Write The Query And Where I Will Call That Query

Regards
<<arali>>
Jan 29 '08 #1
4 1522
debasisdas
8,127 Expert 4TB
try to use th sample
Expand|Select|Wrap|Line Numbers
  1. Dim con As New ADODB.Connection
  2. Dim rs As New ADODB.Recordset
  3.  
  4. Private Sub Command1_Click()
  5. Dim sql As String
  6. con.Open "your connectionstring here"
  7. sql = "your sql query here"
  8. rs.Open sql, con, adOpenDynamic, adLockReadOnly
  9. Text1.Text = IIf(IsNull(rs(0)), "", rs(0))
  10. End Sub
  11.  
  12.  
Jan 29 '08 #2
Killer42
8,435 Expert 8TB
The simplest method would be to throw a data control on the form. Set the properties to connect it to the database, then set the properties of the textbox to connect it to the desired field. The documentation will tell you how.
Jan 29 '08 #3
I Am Using Vb 6
How To Write A Qury In Vb
And Then How And Where To Call That Query ...
Hi
Try this out.
Take a VB6.0 form, place a TextBox and a Command Button on it.
Type this in your click event of command Button.

Expand|Select|Wrap|Line Numbers
  1. Dim rs as New ADODB.Recordset
  2. Dim sSQL As String
  3. Con.Open "Your Connection String (adConnection in my case)"
  4.  
  5. sSQL = "SELECT RollNo FROM Std"
  6.  
  7. rs.Open sSQL, adConnection, adOpenStatic,adLockReadOnly, adCmdText
  8. textbox.Text = rs!RollNo
IMP : But you should have connection with your SQL Server.
Jan 29 '08 #4
I Am Using Vb 6
How To Write A Qury ...
hi arali,
Please check the code.

Expand|Select|Wrap|Line Numbers
  1. Sub getdata()
  2.  
  3. Dim rs As New Adodb.Recordset
  4. Dim strsql As String
  5.  
  6. txtstuname.Text = ""     ' clearing name textbox
  7.  
  8. strsql = "select stuname from students where regno = " & Val(txtregno.Text)
  9. rs.Open strsql, cn
  10. If Not rs.Eof Then
  11.   If Not IsNull(rs(0))
  12.     txtstuname.Text = rs(0)
  13.   End If
  14. End If
  15. rs.Close
  16. set rs = Nothing
  17. End Sub
regards,
vijay
Jan 29 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.