Introduction This article includes a function which can be used as a public function for the applciations involving lots of sql statements that fetches values from the database. This function opens the sql connection with the database. The sql statement has to be passed as a string, the path of the database and the datatable name have to be passed to the function.
Public Function ExecuteSQLCmdFillDataTable(ByVal sql As String, ByVal strTablePath As String, ByRef theDataTable As System.Data.DataTable) As Boolean Dim DONE As Boolean = False
Try sqlConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strTablePath & ";Jet OLEDB:System Database=" & Application.StartupPath & "\SV200SYSTEM.mdw;User Id="";Password="") If sqlConn.State = ConnectionState.Closed Then sqlConn.Open() End If Dim sqlDataAdapter As New OleDbDataAdapter(sql, sqlConn) theDataTable = New System.Data.DataTable sqlDataAdapter.Fill(theDataTable) sqlDataAdapter.Dispose() DONE = True Catch ex As OleDbException MessageBox.Show(ex.ToString, "", MessageBoxButtons.OK, MessageBoxIcon.Error) DONE = False Finally sqlConn.Close() End Try Return DONE End Function
|
No responses found. Be the first to respond and make money from revenue sharing program.
|