Updating Datagrids Simple Problem

desperado

Well-known member
Joined
Oct 7, 2006
Messages
68
Programming Experience
Beginner
Hi, I was wondering if somebody could 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. 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 already, 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:

VB.NET:
 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 Ive got to:

VB.NET:
    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

Any suggestions please? Thanks in advance!
 
Problem is solved!

I just used the wizard and used the update method, its the most easiest.
 
Last edited:
I have used TableAdapter.Fill methods (the click, click, copy-paste easy way) but because this method doesn't give me the kind of flexibility I need for my "application" (searching for names with any letter of the alphabet) I resorted to OleDb. Here is the command which does the job:

myCMD.CommandText = "Select * from Table1 where FN LIKE '" & FNTextBox.Text & "%'"


Could you help me out with the OleDb save/update, delete code? I am not aware of the possibility to use OleDb with wizard.
 
I have used TableAdapter.Fill methods (the click, click, copy-paste easy way) but because this method doesn't give me the kind of flexibility I need for my "application" (searching for names with any letter of the alphabet) I resorted to OleDb.

You cant really "resort" to OleDb.. If youre working with an Access database, the tableadapter uses OleDb.. It writes similar code to what we write, only better and more thorough


Could you help me out with the OleDb save/update, delete code? I am not aware of the possibility to use OleDb with wizard.

Read DW2 link in my sig, sectioon on making a search form. Your param query looks like:

Select * from Table1 where FN LIKE ?

When submitting a value into the parameter, literally send "John%" in as a string. and all records starting with John will be returned
 
it would be a great help and if you are going to study SQL specially its insert command (adding), update command (saving), delete command (deleting )



hehe
 
Back
Top