I don't know it your code is complete.
But because of the fact that you updating using a copy of the datarows,
you've to do the acceptchanges of the dataset after the update.
If you use the dataset to update then the acceptchanges is done inside the
data adapter
Be aware that the adapter is only updating changed, added and deleted rows,
but I see that you want to update alone added rows.
Cor
"Eric" <(E-Mail Removed)> wrote in message
news:ew53gV8$(E-Mail Removed)...
>I thought I needed to accept the add in order to make the getchanges work
>which seemed to be necessary to perform the update.
> Is there any missing or unnecessary code in this program, or do I just
> need to move the acceptchanges statement after the update statement?
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
> news:e%23CqrT6$(E-Mail Removed)...
>> Eric,
>>
>> The answer is the number 1 answer in Net forums and newsgroups.
>>
>> Why do you use the acceptchanges before the update.
>>
>> Acceptchanges means accept all the done changes as updated in the
>> dataset.
>> Therefore any update behind that will do nothing.
>>
>> Success
>>
>> Cor
>>
>>
>> "Eric" <(E-Mail Removed)> wrote in message
>> news:utmUVn2$(E-Mail Removed)...
>>> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>>> System.EventArgs) Handles MyBase.Load
>>> 'TODO: This line of code loads data into the
>>> 'TestDataSet.tableone' table. You can move, or remove it, as needed.
>>> Me.TableoneTableAdapter.Fill(Me.TestDataSet.tableone)
>>> DataGridView1.AutoGenerateColumns = 1
>>> DataGridView1.DataSource = Me.TestDataSet.tableone
>>> End Sub
>>>
>>> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>>> System.EventArgs) Handles Button1.Click
>>> Me.TestDataSet.tableone.AddtableoneRow("1", "Test")
>>> Me.TestDataSet.tableone.AcceptChanges()
>>> Me.TableoneBindingSource.EndEdit()
>>> Dim newChildRecords As TestDataSet.tableoneDataTable = _
>>> CType(TestDataSet.tableone.GetChanges(Data.DataRowState.Added),
>>> TestDataSet.tableoneDataTable)
>>> Me.TableoneTableAdapter.Update(newChildRecords)
>>> End Sub
>>>
>>>
>>> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
>>> news:#7i9lhy$(E-Mail Removed)...
>>>> Eric,
>>>>
>>>> After VB6 with Ado, we have the SqlDataAdapter VB7, the TableAdapter
>>>> VB8, Linq and EF VB9.
>>>>
>>>> So you have a lot of choices, however, as I understand you well you
>>>> have taken the TableAdapter from FrameWork 2.0 and created that using
>>>> drag and drop.
>>>>
>>>> To get the DataGridView filled the best you can do if you have used the
>>>> fill
>>>>
>>>> Dim bs as new BindingSource
>>>> bs.DataSource = TheTable
>>>> TheDataGridView.DataSource = bs
>>>>
>>>> (The latter looks a little bit stupid but the bindingsource repairs
>>>> some issues from past)
>>>>
>>>> The the Update, Insert and Delete commands should be generated when you
>>>> created the adapter as well and the only thing you have to do on the
>>>> place you want to update your table, by instance using a button or the
>>>> menu.
>>>>
>>>> TheTableAdapter.Update(TheTable)
>>>>
>>>> Success
>>>>
>>>> Cor
>>>>
>>>>
>>>> "Eric" <(E-Mail Removed)> wrote in message
>>>> news:%23Io$ZTw$(E-Mail Removed)...
>>>>> I've written a lot of programs and a lot of VB but I'm new to VB.NET
>>>>> so it may be something obvious I'm missing.
>>>>> I created a new project in the .NET Express 2008 IDE.
>>>>> I created a new data with definition (.mdf) with one table.
>>>>> I created a screen program with a grid and a button.
>>>>> I put some code into the program which is supposed to load the data
>>>>> table into the grid on initial startup.
>>>>> I put some code into the button push event to add a new record to the
>>>>> table and update using the tableadapter.
>>>>> When I run the program the grid is blank. When I push the button it
>>>>> adds a row to the grid. I assume it's updating the table. If I push
>>>>> the button again it says cannot add duplicate row. If I exit the
>>>>> program and run it again, the grid comes up blank and pushing the
>>>>> button adds a row. How do I get it to write to the database, to save
>>>>> the data when I exit so the row appears the next time I run it?
>>>>>
>>>>
>>
>
>
|