I've been working with a class module to make my connection codes abit shorter but when i removed my connection from the class and made it public it was not working anymore.
The way I use the class
lcon = New ADOcon
lds = New DataSet
Dim ltb As DataTable = New DataTable
lds = lcon.Opends("Select * from users where uname = '" & uname.ToString & "' and passw ='" & pass.ToString & "'")
can anyone help me solve this problem? here's my class module
Imports System.Data.OleDb
Imports System.Data
Public Class ADOcon
Private daobj As OleDbDataAdapter
Private drobj As OleDbDataReader
Private dsobj As DataSet
Private dtobj As DataTable
#Region "Constructors"
'Public Sub New()
' daobj = New OleDbDataAdapter
' dsobj = New DataSet
' dtobj = New DataTable
'End Sub
#End Region
#Region "Methods"
Public Function Opends(ByVal Query As String) As DataSet
Try
daobj = New OleDbDataAdapter
dsobj = New DataSet
MsgBox(cn.State)
daobj.SelectCommand = New OleDbCommand("Select * from master", cn)
daobj.Fill(dsobj)
MsgBox(dsobj.Tables.Count)
Return dsobj
Catch ex As Exception
Return dsobj
MessageBox.Show(ex.Message, "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Function
Public Function Opendr(ByVal Query As String) As OleDbDataReader
Try
drobj = New OleDbCommand(Query, cn).ExecuteReader
'MsgBox(drobj.HasRows)
Return drobj
Catch ex As Exception
Return drobj
MessageBox.Show(ex.Message, "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Function
Public Sub DatabaseCommand(ByVal CommandString As String)
Try
Dim cmdobj As New OleDbCommand
cmdobj.CommandText = CommandString
cmdobj.Connection = cn
cmdobj.Connection.Open()
cmdobj.ExecuteNonQuery()
'cn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
#End Region
End Class
And this is the connection:
Imports system.data
Imports System.Data.OleDb
Module Main
Public DBpath As String = "c:\ayn data\ayn.mdb"
Public cnstring As String = "Provider=microsoft.jet.oledb.4.0; data source='" & DBpath & "';jet oledb:database password=ayn"
Public cn As OleDbConnection
Sub main()
Dim frmlog As New frmlogin
cn = New OleDbConnection(cnstring)
cn.Open()
frmlog.ShowDialog()
End Sub
End Module
I hope you can help me solve this problem.