Results 1 to 5 of 5

Thread: Updating Datagrids Simple Problem

  1. #1
    desperado is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Oct 2006
    Posts
    68
    Reputation
    120

    Updating Datagrids Simple Problem

    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:

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

    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
    Any suggestions please? Thanks in advance!

  2. #2
    desperado is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Oct 2006
    Posts
    68
    Reputation
    120
    Problem is solved!

    I just used the wizard and used the update method, its the most easiest.
    Last edited by desperado; 03-22-2007 at 5:56 AM.

  3. #3
    cesarfrancisco is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Apr 2007
    Posts
    33
    Reputation
    77
    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.

  4. #4
    cjard's Avatar
    cjard is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2006
    Posts
    7,027
    Reputation
    1705
    Quote Originally Posted by cesarfrancisco View Post
    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

  5. #5
    kyoshiro is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jan 2008
    Posts
    30
    Reputation
    67
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking