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