This snippet shows you how to connect to a database using ODBC in vb.net 2005
Connect to database using ODBC and dot net.
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
greenarcher371 0 Newbie Poster
SoftwarePaladin 0 Newbie Poster
SoftwarePaladin 0 Newbie Poster
sukanya1990 0 Newbie Poster
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.