Howdy, Stranger!

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

Categories

Connecting to a SQL Server Database

InternetGuruInternetGuru Member Posts: 1
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

  • KlaasKlaas Member Posts: 8
    : 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



  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    _____ < http://forcoder.org /> free video tutorials and ebooks about || PHP, Assembly, Objective-C, C++, Go, Scratch, Python, Visual Basic, C#, PL/SQL, Delphi, C, R, MATLAB, Visual Basic .NET, Ruby, JavaScript, Perl, Swift, Java LabVIEW, COBOL, Prolog, Bash, Dart, Clojure, FoxPro, Apex, Transact-SQL, Alice, ABAP, Hack, ML, Lisp, Lua, SAS, Erlang, F#, Fortran, Scheme, Rust, Logo, D, Kotlin, Scala, Crystal, Awk, VBScript, Julia, Ada ||

Sign In or Register to comment.