Accessing DB

I'm new in .NET stuff, can you tell me how can I access databases (MySQL), in VB6 it was ADO.
Thanks.

Comments

  • : I'm new in .NET stuff, can you tell me how can I access databases (MySQL), in VB6 it was ADO.
    : Thanks.
    :

    For MySQL im assuming you will have to use the
    System.Data.OleDB namespace.

    [code]

    Imports System.Data.OleDB

    Private btnOpen_Click(ByVal s As object, ByVal e As EventArgs) _
    Handles btnOpen.Click

    Dim objCon As New OleDBConnection(strConnect)
    Dim objCmd As New OleDBCommand(objCon, strSQL)
    Dim objDR As OleDBDataReader

    objCon.Open
    objDR = objCmd.ExecReader

    Do While objDR.Read
    ' Read Fields
    Loop
    objDR.Close

    End Sub

    [/code]

    This is just a simple example. Im assuming strConnect is a
    variable holding connection string and strSQL is a
    variable holding a SQL SELECT statement.

    If OleDB namesapce does not work, you can always reference
    classic ADO. If u are using Visual Studio.NET, right click
    on project name and choose "Add Reference", then click the
    COM tab. Look for a version of ADO (prob 2.6).
    Visual Studio.NET will automatically create a .NET wrapper
    DLL and place it in the BIN folder and you can
    start creating your recordsets and stuff.

    Good luck.


  • Imports System.Data.SQLClient
    ....

    Private Sub mysub

    Dim Con As New SQLConnection(strConnect)
    Dim Cmd As New SQLCommand(Con, strSQL)
    Dim DR As SQLDataReader
    Dim strConnect as String
    Dim strSQL as String

    strConnect = "provider=............etc"

    strSQL = "SELECT * FROM Table WHERE Field = 'Something'"


    Con.Open

    DR = Cmd.ExecuteReader

    ....

    End Sub



  • Hello,

    Check out this link. I think it should be helpful.

    http://www.mysql.com/articles/dotnet/

    Cheers,
    Chris

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