Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Datagrid [VB.Net Newbie] Please Help

Status
Not open for further replies.

RocAFella2007

Technical User
Mar 21, 2007
45
GB
Hi, Im new to vb if anyone finds the way i talk confusing then im sorry. Could somebody please help me out a little bit as im puzzled. Basically on a form I have a datagrid and some buttons, the buttons are simple and do simple operations. The part im struggling on at the moment is the 'Update' button, the only way I can update at the moment is if someone selects a record from the datagrid and clicks on the 'Edit' button, then another form appears with text boxes where users edit the data and it saves it back into the datagrid. However the help I require is updating records straight away within the datagrid when any record has been changed in the datagrid. For example when a user logs on, they see a datagrid and they change some recrods and select the update button I want the details to get updated automatically in the datagrid, I know about the OleDBDataadapter1.update(Dataset) method but I cant use that as I have coded my datagrid and not relied on the Wizard.

So far to retrieve the details for the datagrid, I Have:

Code:
 Private Sub RetrieveContacts() 
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\AddressBook.mdb") 
        Dim adapter As New OleDbDataAdapter("Select * from Contacts", conn) 
        Dim dt As New DataTable("Contacts") 
        adapter.Fill(dt) 
        dgContacts.DataSource() = dt 
    End Sub 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        RetrieveContacts() 
    End Sub
The above retrieves the details, but I need help on updating.

So far I have tried:
Code:
 Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click 
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\AddressBook.mdb") 
        Dim adapter As New OleDbDataAdapter("Select * from Contacts", conn) 
        Dim dt As New DataTable("Contacts") 
        adapter.Update(dt) 
        dgContacts.DataSource() = dt 
    End Sub
I have also tried
Code:
Dim adapter As New OleDbDataAdapter        
Dim dt As New DataTable("Contacts") 
adapter.Update(dt)

This is really frustrating me so if anybody could help me out or even suggest anything I would really appreciate it.

Thanks in advance!!

 
Not sure about this, but did you try a grid.refresh command just after assigning the datasource?

CraigHartz


CraigHartz
 
Yeh thanks for your suggestion. Its really frustrating me as this is the only part that doesnt work on my program.

If anybody please please could give me any help or suggestions I would really appreciate it.

Thanks.
 
Problem is solved!

I just used the wizard and used the update method, its the most easiest.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top