Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbDataAdapter
Public Class frmGrid
Private Const SELECT_STRING As String = "SELECT * FROM departmentprofile"
Private Const CONNECT_STRING As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\akomykel\Desktop\schoolapp\SchoolApp\obj\Debug\sampledatabase.mdb"
' The DataSet that holds the data.
Private m_DataSet As DataSet
Private data_adapter As New OleDbDataAdapter
Private command_builder As New OleDb.OleDbCommand
Private Sub frmGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create the SqlDataAdapter.
data_adapter = New OleDbDataAdapter(SELECT_STRING, _
CONNECT_STRING)
' Map Table to Contacts.
data_adapter.TableMappings.Add("Table", "departmentprofile")
' Fill the DataSet.
m_DataSet = New DataSet()
data_adapter.Fill(m_DataSet)
' Bind the DataGrid control to the Contacts DataTable.
DataGrid1.SetDataBinding(m_DataSet, "departmentprofile")
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChange
Dim tables As DataTableCollection = m_DataSet.Tables
Dim view1 As New DataView(tables(0))
Dim source1 As New BindingSource()
source1.DataSource = view1
DataGrid1.DataSource = source1
source1.Filter = "fullname Like '" & UCase$(Trim(Mid(TextBox1.Text, 1))) & "%'"
End Sub
End Class
As you can see in my code i had load the tables and filter the records. the only problem is how to update the record from the datagrid. Can anyone help me on what is the code for updating the record directly from the datagrid to the table.
Imports System.Data.OleDb.OleDbDataAdapter
Public Class frmGrid
Private Const SELECT_STRING As String = "SELECT * FROM departmentprofile"
Private Const CONNECT_STRING As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\akomykel\Desktop\schoolapp\SchoolApp\obj\Debug\sampledatabase.mdb"
' The DataSet that holds the data.
Private m_DataSet As DataSet
Private data_adapter As New OleDbDataAdapter
Private command_builder As New OleDb.OleDbCommand
Private Sub frmGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create the SqlDataAdapter.
data_adapter = New OleDbDataAdapter(SELECT_STRING, _
CONNECT_STRING)
' Map Table to Contacts.
data_adapter.TableMappings.Add("Table", "departmentprofile")
' Fill the DataSet.
m_DataSet = New DataSet()
data_adapter.Fill(m_DataSet)
' Bind the DataGrid control to the Contacts DataTable.
DataGrid1.SetDataBinding(m_DataSet, "departmentprofile")
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChange
Dim tables As DataTableCollection = m_DataSet.Tables
Dim view1 As New DataView(tables(0))
Dim source1 As New BindingSource()
source1.DataSource = view1
DataGrid1.DataSource = source1
source1.Filter = "fullname Like '" & UCase$(Trim(Mid(TextBox1.Text, 1))) & "%'"
End Sub
End Class
As you can see in my code i had load the tables and filter the records. the only problem is how to update the record from the datagrid. Can anyone help me on what is the code for updating the record directly from the datagrid to the table.