i am trying to use this code in module page and i called it from FrmEmployee using button to show all Employee information in datagridview
OpenDB() it is a funtion to open connection using oledbconnection
Function New1()
Dim strcmd As String = New String("Select * From Employee")
Co.CommandText = strcmd
Co.Connection = Conn
da.SelectCommand() = Co
OpenDB()
da.Fill(ds, "Employee")
emp.DataGridView1.DataSource = ds.Tables("Employee")
End Function
Imports System.Data.OleDb
Module ModConnection
Public Conn As New OleDbConnection
Dim result As Boolean
Dim StrConn As String
Public Function OpenDB() As Boolean
Try
If Conn.State = ConnectionState.Closed Then
StrConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=Sa;Initial Catalog=HRIS;Data Source=."
Conn.ConnectionString = StrConn
Conn.Open()
result = True
End If
Catch ex As Exception
result = False
End Try
Return result
End Function
End Module