Hello 2 everyone ^_^...
I have a VB code that connects to a sever database and used Virtual Machine as the client (sorry i only have one computer :P).
on the 1st click the select query works, but on the second time it does not work anymore... Here is my code:
From the module
Imports System.Data.OleDb
Module oledb
Public conn As OleDbConnection = New OleDbConnection()
Public comm As OleDbCommand
Public reader As OleDbDataReader
Public query As String
Sub connection()
Try
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\vboxsvr\Documents\sampleDB.mdb;User Id=Admin;Password="
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Module
From the form
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call connection()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
conn.Open()
query = "select * from sample_tbl"
comm = New OleDbCommand(query, conn)
reader = comm.ExecuteReader
While reader.Read
ListBox1.Items.Add("Number: " + reader("number").ToString + "Letter: " + reader("letter").ToString)
End While
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString)
Finally
conn.Dispose()
End Try
End Sub
End Class
The error is
the connectionstring property has not been initialized
The line of error is on the form code
conn.open
Thank you for any help :-)