Query In Vb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arali
    New Member
    • Jan 2008
    • 24

    Query In Vb

    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>>
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    try to use th sample
    [code=vb]
    Dim con As New ADODB.Connectio n
    Dim rs As New ADODB.Recordset

    Private Sub Command1_Click( )
    Dim sql As String
    con.Open "your connectionstrin g here"
    sql = "your sql query here"
    rs.Open sql, con, adOpenDynamic, adLockReadOnly
    Text1.Text = IIf(IsNull(rs(0 )), "", rs(0))
    End Sub

    [/code]

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      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.

      Comment

      • akashazad
        New Member
        • Sep 2007
        • 38

        #4
        Originally posted by arali
        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.

        [CODE=vb]Dim rs as New ADODB.Recordset
        Dim sSQL As String
        Con.Open "Your Connection String (adConnection in my case)"

        sSQL = "SELECT RollNo FROM Std"

        rs.Open sSQL, adConnection, adOpenStatic,ad LockReadOnly, adCmdText
        textbox.Text = rs!RollNo[/CODE]

        IMP : But you should have connection with your SQL Server.
        Last edited by Killer42; Jan 29 '08, 09:52 PM. Reason: Change CODE tag to CODE=vb

        Comment

        • cvraghavan1979
          New Member
          • Jan 2008
          • 28

          #5
          Originally posted by arali
          I Am Using Vb 6
          How To Write A Qury ...
          hi arali,
          Please check the code.

          [CODE=vb]Sub getdata()

          Dim rs As New Adodb.Recordset
          Dim strsql As String

          txtstuname.Text = "" ' clearing name textbox

          strsql = "select stuname from students where regno = " & Val(txtregno.Te xt)
          rs.Open strsql, cn
          If Not rs.Eof Then
          If Not IsNull(rs(0))
          txtstuname.Text = rs(0)
          End If
          End If
          rs.Close
          set rs = Nothing
          End Sub[/CODE]

          regards,
          vijay
          Last edited by Killer42; Jan 29 '08, 09:55 PM. Reason: Added CODE=vb tag

          Comment

          Working...