PC Review


Reply
Thread Tools Rate Thread

How do I create new app with data access?

 
 
Eric
Guest
Posts: n/a
 
      7th Jul 2009
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?


 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      7th Jul 2009
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?
>


 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      7th Jul 2009
I am using a TableAdapter. It is populating a DataGridView control using a
Fill method which was added from the IDE wizard which should be executing on
startup, except it doesn't populate anything on startup. The problem is
it's not saving data. When I execute code from a push button event to add
one dummy record to the table, it automatically displays in the grid, and
executing the same code again gives me a duplicate error on my unique key
field, but when I close and restart the app the grid is blank again. Is it
not writing to the database or is it somehow clearing the table on restart?
Would missing something on the binding cause it not to save? I can paste in
the entire program (about a dozen lines of code) if it helps. As far as I
can tell, the add data table wizard should have created the
update/insert/delete commands.


"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:%237i9lhy$(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?
>>

>



 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      8th Jul 2009
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?
>>

>

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      8th Jul 2009
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?
>>>

>>


 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      8th Jul 2009
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?
>>>>
>>>

>



 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      8th Jul 2009
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?
>>>>>
>>>>

>>

>
>


 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      8th Jul 2009
I created a database (.mdf file) from within the .NET Express IDE and told
it to link it to my VB.NET program and it added the .Fill statement, so I'm
assuming I have to update using a copy of the datarows, so I'm a little
confused as to whether I need to execute methods on the dataset or the
tableadapter or some combination as I did here.

I told it to only update for added rows because my updates only include one
add statement for this test. I searched msdn for sample code on how to
update and it used that method for updating only added rows, within a try
block which had another update for changed and one for deleted. If update
works generic for all types of updates, I'd probably want to do that, since
I'm writing a local single user app which should be able to write changes
one at a time to the database.

Thanks

"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:eZQr4s8$(E-Mail Removed)...
>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



 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      8th Jul 2009
Yes and?

this should have been in my idea enough after adding the row

Me.TableoneTableAdapter.Update(TestDataSet.tableone)

Cor

"Eric" <(E-Mail Removed)> wrote in message
news:uEzqX28$(E-Mail Removed)...
>I created a database (.mdf file) from within the .NET Express IDE and told
>it to link it to my VB.NET program and it added the .Fill statement, so I'm
>assuming I have to update using a copy of the datarows, so I'm a little
>confused as to whether I need to execute methods on the dataset or the
>tableadapter or some combination as I did here.
>
> I told it to only update for added rows because my updates only include
> one add statement for this test. I searched msdn for sample code on how
> to update and it used that method for updating only added rows, within a
> try block which had another update for changed and one for deleted. If
> update works generic for all types of updates, I'd probably want to do
> that, since I'm writing a local single user app which should be able to
> write changes one at a time to the database.
>
> Thanks
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
> news:eZQr4s8$(E-Mail Removed)...
>>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

>
>


 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      8th Jul 2009
So, do I need any references to the dataset or the bindingsource, or just do
this?

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.TableoneTableAdapter.Update(TestDataSet.tableone)
Me.TestDataSet.tableone.AcceptChanges()
End Sub


"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:O0QfT98$(E-Mail Removed)...
> Yes and?
>
> this should have been in my idea enough after adding the row
>
> Me.TableoneTableAdapter.Update(TestDataSet.tableone)
>
> Cor
>
> "Eric" <(E-Mail Removed)> wrote in message
> news:uEzqX28$(E-Mail Removed)...
>>I created a database (.mdf file) from within the .NET Express IDE and told
>>it to link it to my VB.NET program and it added the .Fill statement, so
>>I'm assuming I have to update using a copy of the datarows, so I'm a
>>little confused as to whether I need to execute methods on the dataset or
>>the tableadapter or some combination as I did here.
>>
>> I told it to only update for added rows because my updates only include
>> one add statement for this test. I searched msdn for sample code on how
>> to update and it used that method for updating only added rows, within a
>> try block which had another update for changed and one for deleted. If
>> update works generic for all types of updates, I'd probably want to do
>> that, since I'm writing a local single user app which should be able to
>> write changes one at a time to the database.
>>
>> Thanks



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CREATE A Data Access Page From An ACCESS Report Mike S. S. Microsoft Access Reports 0 27th Jan 2009 09:01 PM
How do I create a data access page in Access 2007? =?Utf-8?B?RGlhbmUgU25vd2Rlbg==?= Microsoft Access 4 20th Apr 2007 03:20 PM
data access pages: how to create search engine & guestbook ??? (access 2000) Jamie Carpenter via AccessMonster.com Microsoft Access Database Table Design 1 2nd Mar 2005 03:38 AM
data access pages: how to create search engine & guestbook ??? (access 2000) Jamie Carpenter via AccessMonster.com Microsoft Access Forms 0 1st Mar 2005 09:02 PM
WHEN I Create A Access Data base It won`t Create a Switchboard ?. =?Utf-8?B?R2FyZXRo?= Microsoft Access Getting Started 2 14th Sep 2004 02:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:46 AM.