Connecting to a SQL Server Database

I am new to the world of VB programming and I need to write some code that will connect a GUI interface to a SQL Server DB. I would like to connect to the database from a push of a button. Once the the connection is made I then need to list the data from a specific table in form. The ability to push a button to get the next data in the form is also needed.

Comments

  • : I am new to the world of VB programming and I need to write some code that will connect a GUI interface to a SQL Server DB. I would like to connect to the database from a push of a button. Once the the connection is made I then need to list the data from a specific table in form. The ability to push a button to get the next data in the form is also needed.
    :

    Ok, either you use a ODBC connection or you write the connection string.
    An easy way to write your connectionstring is by placing an ActiveX data control on you form and select use a connection string. next you click build and off you go.


    =================================================================
    =================================================================

    Public g_cnx as Adodb.Connection

    Public sub DbConnect(ConnectionString as String)

    set g_cnx = new adodb.connection
    g_cnx.open connectionstring 'f.e.

    End sub

    Public Function GetDbValue()

    Dim rs as Adodb.Recordset
    set rs = new adodb.recordset
    rs.open "Select * From tblTest", g_cnx, adOpenKeyset, adLockOptimistic
    'The second param is a connection which was already defined in the previous sub.

    rs.filter = "[name] = '" & InputBox("What's your name?") & "'"
    if rs.recordcount < 1 then
    msgbox "Not found"
    Else
    MsgBox rs.Fields("name").value 'or rs!name easier
    end if

    End Function



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion