Hey guys I'ld really appreciate if u can help me with this.
I'm building an application that has an access database for storing codes for voters.
my problem is that after i update my database with the usual vb codes, i'll have to exit the application before the datagrid view can read the update. please is there a way for me to see the changes i've made with the datagrid view without my exiting the application. I'm using vb 2010 express. thanks guys
It's very simple, just after your Save button or you can make a refresh button you can add the code to fill the datagrid view again.
For example I have a Save button, I did the code "insert into......." after the the code which saves the query you will add
Dim Myrd As SqlDataReader
Dim Mytb As New DataTable
Mycmd.CommandText = "Select statement which retrieves the Table contents"
Myrd = Mycmd.ExecuteReader()
datagridview.DataSource = Mytb
You are going to add this code each time you want to refresh you datagrid view.
Hope this helps you.
it's actually pretty simple. Create a sub with the code you've used to populate the datagrid in the first place and call that sub whenever you want to load data into the datagrid (on form load, after an insert/update/delete or on a button click event).
Thanks Danthevan and Adam, but i'm still a little lost...i'm pretty new to this stuff, especially linking with databases.
I've tried the code u gave me but i'm having trouble with the line 4 of the code u gave @danthevan. an example of the statement u want on that line might help out...or if u've got another way, it will be a big help.
Private Sub btnLoad_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Using conExercise As SqlConnection = _
New SqlConnection("Data Source=(local);" & _
"Database='Exercise';" & _
Dim strExercise As String = "SELECT * FROM Employees"
Dim cmdExercise As SqlCommand = New SqlCommand(strExercise, _
Dim sdaExercise As SqlDataAdapter = New SqlDataAdapter(cmdExercise)
Dim dsExercise As DataSet = New DataSet("ExerciseSet")
dgvExercise.DataSource = dsExercise
dgvExercise.DataMember = dsExercise.Tables(0).TableName