swethajain
Well-known member
- Joined
- Feb 1, 2010
- Messages
- 48
- Programming Experience
- Beginner
Hi
Let's say that I have a windows application in which I have a form with some controls that are bound to a dataset. A DataAdapter or TableAdapter fills the dataset on form load with a large number of records and user can navigate and change the details for each record. This works fine ... but this app runs on a network. And let's say meanwhile you've loaded your form and you're navigating through it (for half an hour let's say whithout saving changes or reloading the dataset) another user modifes the data and updates the database but as long as you have your application running you can't see those changes !!! what is the method to know whether the database has been updated or how to refresh the datagrid view with the new changes updated by other users while the application is running?
code is
Imports System.Data.OleDb
Public Class Main_Page
Private Sub Main_Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Status' table. You can move, or remove it, as needed.
Me.StatusTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Status)
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Priority' table. You can move, or remove it, as needed.
Me.PriorityTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Priority)
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Owner' table. You can move, or remove it, as needed.
Me.OwnerTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Owner)
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Project_Details' table. You can move, or remove it, as needed.
Me.Project_DetailsTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Project_Details)
datagrid_width()
End Sub
Public Function datagrid_width()
Project_DetailsDataGridView.Columns(0).Width = 220
Project_DetailsDataGridView.Columns(1).Width = 160
Project_DetailsDataGridView.Columns(2).Width = 110
Project_DetailsDataGridView.Columns(3).Width = 110
Project_DetailsDataGridView.Columns(4).Width = 110
Project_DetailsDataGridView.Columns(5).Width = 110
End Function
Private Sub bt_Add_New_Project_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Add_New_Project.Click
Add_New_Project.Show()
End Sub
Private Sub bt_Edit_Project_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Edit_Project.Click
Edit_Project.Show()
End Sub
Private Sub Project_DetailsDataGridView_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Project_DetailsDataGridView.CellEndEdit
Dim row_index As Integer = e.RowIndex
Dim project_name As String = Project_DetailsDataGridView.Item(0, row_index).Value.ToString
Dim owner As String = Project_DetailsDataGridView.Item(1, row_index).Value.ToString
Dim priority As String = Project_DetailsDataGridView.Item(2, row_index).Value.ToString
Dim status As String = Project_DetailsDataGridView.Item(3, row_index).Value.ToString
Dim start_date As Date = Project_DetailsDataGridView.Item(4, row_index).Value
Dim end_date As Date = Project_DetailsDataGridView.Item(5, row_index).Value
Try
myconnection.Open()
Dim str_updt As String = "update [Project_Details] set status='" & status & "',priority='" & priority & "',[Start_Date]=#" & start_date & "#,[End_Date]=#" & end_date & "#,[Owner]='" & owner & "' where [project_name]='" & project_name & "' "
Dim cmd As New OleDbCommand(str_updt, myconnection)
cmd.ExecuteNonQuery()
myconnection.Close()
Me.Project_DetailsTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Project_Details)
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class
Thanks
Let's say that I have a windows application in which I have a form with some controls that are bound to a dataset. A DataAdapter or TableAdapter fills the dataset on form load with a large number of records and user can navigate and change the details for each record. This works fine ... but this app runs on a network. And let's say meanwhile you've loaded your form and you're navigating through it (for half an hour let's say whithout saving changes or reloading the dataset) another user modifes the data and updates the database but as long as you have your application running you can't see those changes !!! what is the method to know whether the database has been updated or how to refresh the datagrid view with the new changes updated by other users while the application is running?
code is
Imports System.Data.OleDb
Public Class Main_Page
Private Sub Main_Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Status' table. You can move, or remove it, as needed.
Me.StatusTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Status)
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Priority' table. You can move, or remove it, as needed.
Me.PriorityTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Priority)
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Owner' table. You can move, or remove it, as needed.
Me.OwnerTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Owner)
'TODO: This line of code loads data into the 'Lusail_Test_DBDataSet.Project_Details' table. You can move, or remove it, as needed.
Me.Project_DetailsTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Project_Details)
datagrid_width()
End Sub
Public Function datagrid_width()
Project_DetailsDataGridView.Columns(0).Width = 220
Project_DetailsDataGridView.Columns(1).Width = 160
Project_DetailsDataGridView.Columns(2).Width = 110
Project_DetailsDataGridView.Columns(3).Width = 110
Project_DetailsDataGridView.Columns(4).Width = 110
Project_DetailsDataGridView.Columns(5).Width = 110
End Function
Private Sub bt_Add_New_Project_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Add_New_Project.Click
Add_New_Project.Show()
End Sub
Private Sub bt_Edit_Project_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Edit_Project.Click
Edit_Project.Show()
End Sub
Private Sub Project_DetailsDataGridView_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Project_DetailsDataGridView.CellEndEdit
Dim row_index As Integer = e.RowIndex
Dim project_name As String = Project_DetailsDataGridView.Item(0, row_index).Value.ToString
Dim owner As String = Project_DetailsDataGridView.Item(1, row_index).Value.ToString
Dim priority As String = Project_DetailsDataGridView.Item(2, row_index).Value.ToString
Dim status As String = Project_DetailsDataGridView.Item(3, row_index).Value.ToString
Dim start_date As Date = Project_DetailsDataGridView.Item(4, row_index).Value
Dim end_date As Date = Project_DetailsDataGridView.Item(5, row_index).Value
Try
myconnection.Open()
Dim str_updt As String = "update [Project_Details] set status='" & status & "',priority='" & priority & "',[Start_Date]=#" & start_date & "#,[End_Date]=#" & end_date & "#,[Owner]='" & owner & "' where [project_name]='" & project_name & "' "
Dim cmd As New OleDbCommand(str_updt, myconnection)
cmd.ExecuteNonQuery()
myconnection.Close()
Me.Project_DetailsTableAdapter.Fill(Me.Lusail_Test_DBDataSet.Project_Details)
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
End Class
Thanks
Last edited: