vb.net refresh datagridview every 20 second - vb.net

I want to ask how to refresh and update the datagridview data every 20 second.
What I want is when I adding the data into database, datagrdview will refresh and show the latest data that in database.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
dgvRecord.Refresh()
End Sub
I tried in this way but it's no work.
Database part is OK but i had problem at refresh datagridview part.
hope can help me solve the question ,thank you!

Related

Delete selected row in Datagridview

I have a datagridview in which I want to insert a button for removing the selected row. I created without any problems the AddRow Button and, following the same idea, I tried to create the RemoveRow button with the following code:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
DataGridView2.Rows.Remove()
End Sub
When I start debugging I'm having BC30455 error, about not specified argument. What am I doing wrong? I tried to find out here in the forum but I've found only sth about C# and not VB.net
Best regards and thanks all are gonna answer me.

How do i update different table from the same access database using visual basic .net

I added my Enrollment system access Database, into my Enrollment System vb.net form, as a data source. The Database has 2 tables in it, the accountTable and studentEnrollmentInformation. I dragged The accountTable's details and data grid view into my form designer. The following code automatically appeared in the code designer:
Private Sub AccountTableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
Me.Validate()
Me.AccountTableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
End Sub
Private Sub enrollmentSystem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
End Sub
The following code works for updating the accounTableDataGridView but it does not work for studentEnrollmentInformationDataGridView so i manually created one
for studentEnrollmentInformation.
Function updateStudent()
Me.Validate()
Me.StudentEnrollmentInformationBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
Me.StudentEnrollmentInformationTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.studentEnrollmentInformation)
End Function
This is the function that contains the update code, that i manually created for updating the studentEnrollmentDataGridView. Adding new Row works fine but when i try to update studentEnrollmentDataGridView the texts in the table disappears and does not update/save. I also had function for updating the accountTableDataGridView which works fine.
Function update() 'THIS FUNCTION CONTAINS PRE-MADE CODE TO MAKE UPDATING SHORTER IN WRITING CODE.
Me.Validate()
Me.AccountTableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
End Function
My Question is how do i update multiple Tables in my system? Updating the other table works fine but the other is not.
In the original auto-generated code, this is the line that retrieves the data in the first place:
Private Sub enrollmentSystem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
End Sub
When the form loads, the Account data is retrieved into a DataTable that is already bound. If you want to retrieve Student Enrollment data too, do it in the same place:
Private Sub enrollmentSystem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
Me.StudentEnrollmentInformationTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.studentEnrollmentInformation)
End Sub
Now you're populating both bound DataTables when the form loads. When it comes to saving, you do the same thing, i.e. add the code to save the changes to the other DataTable where you already have the code to save the first:
Private Sub AccountTableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
Me.Validate()
Me.AccountTableBindingSource.EndEdit()
Me.StudentEnrollmentInformationBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
End Sub
You don't need any code to specifically save the changes from the DataTable because the whole point of UpdateAll is that it updates all DataTables in the DataSet.
As is always the case, if it doesn't seem to be working as you expect then you debug it. In that case, that would mean setting a breakpoint on the UpdateAll line and examining the exact state of the DataSet before and after the call, as well as possibly examing the sate of the database too.

How should I reset my application using vb2008 except for the last form?

So, I made an application which composes several forms. It contains saving scores at the end of the game(form). However, when I try to reset the game, it resets all the data with this code:
Private Sub ResetDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetDataToolStripMenuItem.Click
Application.Restart()
Me.Refresh()
I only want to reset all forms except for the scoretable form which is the last form. Can you give me the easiest way to solve my problem?
P.S I am a newbie for this. Please help me guys. This will serve as my quarterly exam. I need to pass.

Update changes made in datagridview into Access 2016

I made a connection with an Access database (Access 2016) using dataset, bindingsource, tableadapter, bindingnavigator, and datagridview.
It works, I can navigate in the datagridview, make changes, add and delete records in the datagridview, but these changes don't appear in the Access DB.
Data is loaded with:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'FacturatieDataSet.Catalogus' table. You can move, or remove it, as needed.
CatalogusTableAdapter.Fill(FacturatieDataSet.Catalogus
End Sub
For deleting I use:
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
CatalogusBindingSource.RemoveCurrent()
CatalogusTableAdapter.Update(FacturatieDataSet.Catalogus)
End Sub
I'm new with VB 2015, I'm not a programmer, I do this for personnal study.
What is an (easy) solution to my problem?
You fill the datagridview but you don't update it (except when you delete a record).
Look up a tutorial on how to handle basic CRUD operations with a datagridview.

vb.net connects to database access

im really new to this language so this is so simple please answer
Me.InfoBindingSource.RemoveCurrent()
i only have id t on my delete button do i have to adsome codes? knows anyone?
i've searched some sites and it is the only code they say. i connected it and actually worked on add. but with delete it dont.
Do i need to move something.. like files?
i've tried everything this is my last hope. thanks for the answer :)
here is the whole code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.InfoBindingSource.RemoveCurrent()
End Sub
That RemoveCurrent method will mark the current row in the bound DataTable as Deleted. Just like when adding or editing rows though, you still have to call Update on your data adapter or table adapter to save that change back to the database.