Latest News

the latest news from our team

VB.NET Sample Using ODBC .NET Data Provider and ADO

 

Download the sample: [HTTP]

 

Imports Microsoft.Data.Odbc

Public Class Form1
Inherits System.Windows.Forms.Form

#Region ” Windows Form Designer generated code ”

Public Sub New()
MyBase.New()

‘This call is required by the Windows Form Designer.
InitializeComponent()

‘Add any initialization after the InitializeComponent() call

End Sub

‘Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

‘Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

‘NOTE: The following procedure is required by the Windows Form Designer
‘It can be modified using the Windows Form Designer.
‘Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents password As System.Windows.Forms.TextBox
Friend WithEvents hpgroup As System.Windows.Forms.TextBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.password = New System.Windows.Forms.TextBox()
Me.hpgroup = New System.Windows.Forms.TextBox()
Me.Button2 = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.SuspendLayout()

‘Button1

Me.Button1.Location = New System.Drawing.Point(136, 24)
Me.Button1.Name = “Button1”
Me.Button1.Size = New System.Drawing.Size(112, 30)
Me.Button1.TabIndex = 2
Me.Button1.Text = “Use ADO”

‘TextBox1

Me.TextBox1.Location = New System.Drawing.Point(192, 200)
Me.TextBox1.Name = “TextBox1”
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(200, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.TabStop = False
Me.TextBox1.Text = “TextBox1”

‘password

Me.password.Location = New System.Drawing.Point(192, 96)
Me.password.Name = “password”
Me.password.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.password.Size = New System.Drawing.Size(200, 20)
Me.password.TabIndex = 0
Me.password.Text = “”

‘hpgroup

Me.hpgroup.Location = New System.Drawing.Point(192, 136)
Me.hpgroup.Name = “hpgroup”
Me.hpgroup.Size = New System.Drawing.Size(200, 20)
Me.hpgroup.TabIndex = 1
Me.hpgroup.Text = “PUB”

‘Button2

Me.Button2.Location = New System.Drawing.Point(280, 24)
Me.Button2.Name = “Button2”
Me.Button2.Size = New System.Drawing.Size(112, 32)
Me.Button2.TabIndex = 3
Me.Button2.Text = “Use ODBC .NET”

‘Label1

Me.Label1.Location = New System.Drawing.Point(88, 96)
Me.Label1.Name = “Label1”
Me.Label1.Size = New System.Drawing.Size(88, 24)
Me.Label1.TabIndex = 4
Me.Label1.Text = “User Password”

‘Label2

Me.Label2.Location = New System.Drawing.Point(88, 136)
Me.Label2.Name = “Label2”
Me.Label2.Size = New System.Drawing.Size(88, 24)
Me.Label2.TabIndex = 5
Me.Label2.Text = “HP Group”

‘Label3

Me.Label3.Location = New System.Drawing.Point(88, 200)
Me.Label3.Name = “Label3”
Me.Label3.Size = New System.Drawing.Size(88, 24)
Me.Label3.TabIndex = 6
Me.Label3.Text = “Sample Result”

‘Form1

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 374)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.Label2, Me.Label1, Me.Button2, Me.hpgroup, Me.password, Me.TextBox1, Me.Button1})
Me.Name = “Form1”
Me.Text = “Form1”
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New ADODB.Connection()
Dim rs As New ADODB.Recordset()

TextBox1.Text = “busy…”
Application.DoEvents()

conn.Open(“DRIVER=HP3000 Data Access Driver;” & _
“2DriverTable=;” & _
“Database0=MSCARD.MM.MINISOFT,DO-ALL,N,1;” & _
“2HostTable=Customers;” & _
“Server=192.168.23.70;” & _
“Server Port=2185;” & _
“Jobname=MSJOB;” & _
“User=MGR;” & _
“User Password=” & password.Text & “;”& _
“Group=” & hpgroup.Text & “;” & _
“Account=MINISOFT”)

rs.Open(“SELECT * FROM CUSTOMER”, conn)

rs.MoveFirst()

TextBox1.Text = CStr(rs.Fields(2).Value)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim conn As New OdbcConnection()

Dim myConnString As String = _
“DRIVER=HP3000 Data Access Driver;” & _
“2DriverTable=;” & _
“Database0=MSCARD.MM.MINISOFT,DO-ALL,N,1;” & _
“2HostTable=Customers;” & _
“Server=192.168.23.70;” & _
“Server Port=2185;” & _
“Jobname=MSJOB;” & _
“User=MGR;” & _
“User Password=” & password.Text & “;” & _
“Group=” & hpgroup.Text & “;” & _
“Account=MINISOFT”

Dim mySelectCommandText As String = _
“SELECT * FROM CUSTOMER”

TextBox1.Text = “busy…”
Application.DoEvents()

conn.ConnectionString = myConnString

conn.Open()

Dim myCommand As New OdbcCommand(mySelectCommandText, conn)
Dim myReader As OdbcDataReader
myReader = myCommand.ExecuteReader()
If myReader.Read() Then
TextBox1.Text = myReader.GetString(2)
Else
TextBox1.Text = “error”
End If

End Sub
End Class

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code