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

Recommended Answers

All 5 Replies

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()

        Mytb.Load(Myrd)

        datagridview.DataSource = Mytb
        Myrd.Close()

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.
Thanks again.

Thanks guys...i found a way to do it...although i dont really understand the code i used, but i found a way to make it work. thanks again

This was the code i manipulated to get my results...i got it from www.functionx.com

Private Sub btnLoad_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles btnLoad.Click
        Using conExercise As SqlConnection = _
   			New SqlConnection("Data Source=(local);" & _
                                          "Database='Exercise';" & _
                                          "Integrated Security=SSPI;")
            Dim strExercise As String = "SELECT * FROM Employees"
            Dim cmdExercise As SqlCommand = New SqlCommand(strExercise, _
							   conExercise)
            Dim sdaExercise As SqlDataAdapter = New SqlDataAdapter(cmdExercise)
            Dim dsExercise As DataSet = New DataSet("ExerciseSet")

            sdaExercise.Fill(dsExercise)
            dgvExercise.DataSource = dsExercise
            dgvExercise.DataMember = dsExercise.Tables(0).TableName
        End Using
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.