Connect to database using ODBC and dot net.

iamthwee 0 Tallied Votes 5K Views Share

This snippet shows you how to connect to a database using ODBC in vb.net 2005

Imports System.Data.Odbc

Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myConnection As OdbcConnection = New OdbcConnection()
        myConnection.ConnectionString = "Dsn=epic;uid=SYSPROG;host=server4;port=8350;db=mfgsys803"

        myConnection.Open()


        Dim cmdtxt As String
        ' Dim no As Integer
        Dim myCommand As New OdbcCommand()

        'Try
        '    conection.Open()
        'Catch ex As Exception

        'End Try
        myCommand.Connection = myConnection
        Dim myAdapter As New OdbcDataAdapter



        cmdtxt = "SELECT pub.Part.PartNum, pub.Part.ClassID FROM   PUB.Part Part WHERE  pub.Part.PartNum='50101001'"

        'cmdtxt = "SELECT pub.Part.PartNum FROM pub.Part"

        MessageBox.Show(cmdtxt)


        myCommand.CommandText = cmdtxt 'start query
        myAdapter.SelectCommand = myCommand

        Dim moddata As OdbcDataReader

        moddata = myCommand.ExecuteReader()


        While moddata.Read = True
            Try
                MessageBox.Show(moddata(1))
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End While

        moddata.Close()


        myConnection.Close()

    End Sub
End Class
milanbillara 0 Newbie Poster

can you tell me the connection to access database using odbc and vb.net please.

greenarcher371 0 Newbie Poster

give me example code for electronic photo album by use dragging the image to the other position or other frame, example image1 with picture input drag to image2 no picture input by using mouse control and code for locating file in listcommand?

SoftwarePaladin 0 Newbie Poster

i have been having some problems with this coding m8 do u mind give me more information on:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim myConnection As OdbcConnection = New OdbcConnectio () myConnection.ConnectionString = " "

Please help me out
this is my email: H_W_S.oforikue.16@hotmail.com

anyone that know not only author of code if u know more about this piece of coding cos it is not working

SoftwarePaladin 0 Newbie Poster

yea about my earlier post i figured it out ty

sukanya1990 0 Newbie Poster

This snippet shows you how to connect to a database using ODBC in vb.net 2005

can you please tell me how to get the connection string ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.