Results 1 to 2 of 2

Thread: Update DataTable

  1. #1

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Angry Update DataTable

    I have a TextBox, BindingSource, DataSet and TableAdapter....

    I want to update the database with the text from that textbox!

    Code:
            Dim DataRow As Data.DataRow
    
            DataRow("denumire") = Me.txt_denumire_unitate.Text
    
    (Me.Ibooks_datele_unitatii_DataSet, "datele_unitatii").EndCurrentEdit()
            Me.Ibooks_datele_unitatii_DataSet.Tables("datele_unitatii").Rows.Add(DataRow)
    
    
            Me.Datele_Unitatii_BindingSource.EndEdit()
            Me.datele_unitatii_TableAdapter.Update(Me.Ibooks_datele_unitatii_DataSet.datele_unitatii)
    What's wrong with this ?!
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Update DataTable

    You're trying to set a field of a nonexistent DataRow. Look at this code:
    Code:
            Dim DataRow As Data.DataRow
    
            DataRow("denumire") = Me.txt_denumire_unitate.Text
    The first line declares a variable named "DataRow" that is type DataRow. Congratulations, you now have a variable that CAN refer to a DataRow object but at the moment refers to Nothing. The next line tries to set the "denumire" column of the DataRow object referred to by that variable to a value. If the variable doesn't refer to a DataRow object though, how can you set a field?

    Think about this. If you go and build a garage on the side of your house, does that mean that you can just jump in and drive the car it contains? Of course not. You have actually put a car inside it first. Just because you've got somewhere to put a car doesn't mean you've got a car. Likewise, just because you've got a variable that can refer to a DataRow doesn't mean you've got a DataRow.

    Also, this line is completely meaningless:
    Code:
    (Me.Ibooks_datele_unitatii_DataSet, "datele_unitatii").EndCurrentEdit()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width