AllExperts > Experts 
Search      

Visual Basic

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ravindra
Expertise
visual basic application programming from design to access information, sql, engineering and commercial applications. access databases, excel. Optional: 1)a large number of people want me to do work which takes some time and effort. Pl.note that i would like to be paid for such work. 2) if you want me to spend quality time and do special work, i expect to be paid a reasonable price for my time. 3) if you are pleased with my reply you could consider a donation of 1$. 4) you can visit my website http://ravindra.coolpage.biz (under constrn)

Experience

Past/Present clients
project work for a Norway company, and a Canadian company completed. Freelance Project work and Teaching
teaching vb

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > To retrive records from sql database

Topic: Visual Basic



Expert: Ravindra
Date: 7/12/2008
Subject: To retrive records from sql database

Question
Sir My query is how to retrieve records from sql database and display it into textbox .M  using vb6

Answer
sample code:

always use a label or grid to display results and not a textbox as the user may change values.

Option Explicit
'checkmark on Project-References-Microsoft ActiveX dataobjects library
Dim cn As ADODB.Connection, esql As String, rec As Recordset


Private Sub Command1_Click()
If rec.EOF Then Exit Sub
Label4.Caption = rec.Fields(0)
Label5.Caption = rec.Fields(1)
Label6.Caption = rec.Fields(2)

End Sub

Private Sub Command2_Click()
If Not rec.EOF Then rec.MoveNext
Call Command1_Click
End Sub

Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rec = New ADODB.Recordset
cn.Open ("Driver={SQL Server};Server=Ravindra;Database=test;Uid=sa;Pwd=;")
esql = "select * from testable"
rec.Open (esql), cn
Label4.Caption = rec.Fields(0)
Label5.Caption = rec.Fields(1)
Label6.Caption = rec.Fields(2)


End Sub

Private Sub Form_Unload(Cancel As Integer)
  rec.Close

  cn.Close
End Sub
'make suitable changes


Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.