473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB & ADO.Net - Problems adding data

Hello!

I'm just trying to add a new row of data to a dataset, but whenever the form is closed, it loses the data.

...
Case "Add"
TgtRw = ElementsDataSet.Tables("Elements").NewRow()
TgtRw("EID") = Guid.NewGuid
TgtRw("AL_ID") = Key
TgtRw("EType") = "R"
ElementsDataSet.Tables("Elements").Rows.Add(TgtRw)
ElementsDataSet.Tables("Elements").AcceptChanges()
End Select
ElementsDataSet.AcceptChanges()
End Sub


The form contains a gridview which is linked to the dataset, but not used for editing the data.
While the form is open, the new datarows are visible in the gridview. Everything works fine until the form is closed - reopened, the tables are empty.

btw: VS 2005; SQLExpress

Can anyone help?
Thanks!
Mar 16 '08 #1
4 1009
nateraaaa
663 Expert 512MB
After you change the dataset are you inserting the data into your database? If AcceptChanges is successful you should then insert the row into your database. Then when you close and reopen the form (populating the data in the page when it opens) the data that was added should be in the form because it was added to your database.

Nathan
Mar 17 '08 #2
After you change the dataset are you inserting the data into your database? If AcceptChanges is successful you should then insert the row into your database. Then when you close and reopen the form (populating the data in the page when it opens) the data that was added should be in the form because it was added to your database.

Nathan
Hello Nathan!

I learned that I have to update the database with the changes, so I tried this before leaving the sub:
Try
ElementsTableAdapter.Update(ElementsDataSet.elemen ts)
Catch ex As Exception
MsgBox("Update failed")
End Try
But any changes to the dataset are still not send to the database.

When I reopen the form the data added direktly to database (via server explorer) is shown normally - so the query seems to work - but the changes not.

I really have no idea ...

Thanks for your help.

Stefan
Mar 17 '08 #3
nateraaaa
663 Expert 512MB
[font=Verdana][size=2]If you are adding new data to the database you would need to call an insert stored procedure. If you are updating a current record you would call and update stored procedure. I would call an insert stored procedure after your AcceptChanges method in your "Add" case. Give this a try and let us know how it works for you.[/size][/font]
[font=Verdana][size=2][/size][/font]
[font=Verdana][size=2]Nathan[/size][/font]
Mar 17 '08 #4
[font=Verdana][size=2]If you are adding new data to the database you would need to call an insert stored procedure. If you are updating a current record you would call and update stored procedure. I would call an insert stored procedure after your AcceptChanges method in your "Add" case. Give this a try and let us know how it works for you.[/size][/font]
[font=Verdana][size=2][/size][/font]
[font=Verdana][size=2]Nathan[/size][/font]

I've got it! - you gave me the right hint !

- The update-command of the table-adapter automatically uses the right SQL-statement according to the state-property of the rows
- the "acceptchanges"-command resets the state-propeties of the added rows so that the update doesn't identify the new rows to be send to the server ...

-> so I left out the AcceptChanges-command and everything seems to work well


Thanks for the help!

Stefan
Mar 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
47
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
20
by: wolftor | last post by:
Would anyone be willing to beta test my application for me and give me some feedback? I can give you feedback in exchange (ie. if there are parts you're interested in knowing how it was done) or I...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
7
by: Sascha Schmidt | last post by:
Hello ! I have a little problem accessing a Visual Foxpro-database using ODBC (Driver 6.00.8167) (using System.Data.Odbc). Reading a column, defined in the Foxpro table definition as a kind of...
1
by: InBiz_Dev | last post by:
I am new to .NET developmet so please excuse any stupid questions. I am trying to develop a web application that will include data forms and crystal reports. Our infrastructure is such that...
6
by: Suzanne | last post by:
Hi all, I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
7
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.