By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,982 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,982 IT Pros & Developers. It's quick & easy.

Query In Vb

P: 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
Share this Question
Share on Google+
4 Replies


debasisdas
Expert 5K+
P: 8,127
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

Expert 5K+
P: 8,434
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

akashazad
P: 38
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

P: 28
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

Post your reply

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