Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataSet Changes - Show unchanged

Status
Not open for further replies.

LovinIt

Programmer
Dec 20, 2004
17
US
Hi,

I am hoping someone could give me a clue...

I am working with VB.NET and have done the following...
------------------For the form declarations-----------------
Public sConnection = <<DECLARED PROPERLY>>
Friend SqlConnection As System.Data.SqlClient.SqlConnection
Friend sqlAdapter As System.Data.SqlClient.SqlDataAdapter
Friend sqlCmd As System.Data.SqlClient.SqlCommand
Friend dsInfo
Friend sqlCmdBuilder As System.Data.SqlClient.SqlCommandBuilder

------------------------the Load event--------------------
SqlConnection = New SqlConnection(sConnection)
sqlCmd = New SqlCommand("SELECT PeopleID, Directory, PublishIt, FirstName, LastName, Address1, Address2, Address3, Zip, City, State, Country, Phone, Fax, Website, Email, DatelastModified from tPeople", SqlConnection)
sqlAdapter = New SqlDataAdapter(sqlCmd)

sqlCmdBuilder = New SqlCommandBuilder(sqlAdapter)
dsInfo = New DataSet
SqlConnection.Open()

sqlCmd.CommandText = "SELECT PeopleID, Directory, PublishIt, FirstName, LastName, Address1, Address2, Address3, Zip, City, State, Country, Phone, Fax, Website, Email, DatelastModified from tPeople"
sqlAdapter.Fill(dsInfo, "Services")

-----------------the button click-------------------
dsInfo.Tables("services").Rows(0).BeginEdit()
dsInfo.Tables("Services").Rows(0).Item("Address1") = "1111"
dsInfo.Tables("services").Rows(0).EndEdit()
dsInfo.Tables("services").Rows(0).AcceptChanges()
sqlAdapter.Update(dsInfo, "Services")
dsInfo.AcceptChanges()

----------------comments----------------------------
I put a break on the AcceptChanges line to see the RowState for that particular row and it is classified as "unchanged"

Even though the Row shows the new value and once the click code is finished the *text box* on the *form* for address1 does get updated to that value.

It won't save to the database either.

Other case is if I type something in a text box itself (instead of using code behind) it does the same thing. the Row adn field itself reflects the changes. However, the row state is classified as "unchanged" and it won't save to the database.

So whether I use a form to put in the value to the dataset or use code behind and do it by hand, I am not getting it to work.

What am I doing wrong? I know I must be missing something.. Either that or the gremlins got my computer :)

Any help is greatly appreciated!

Angela
 
Take out the call to the row's .AcceptChanges() before you Update.
 
Hi RiverGuy,

Thanks for the tip. The manual example works now.

I am trying to get the typing into the form to work.

Can I verify something with you.

Whenever, a record is loaded up into the form fields from the dataset. I must tell the program to do a beginEdit on that record(dataset row)? And then when I save I must tell it to endEdit on that specific record(dataset row)?

Actually when I don't do this the form doesn't save anything to the database. You can see the changes to the dataset but it won't update the database.

I am not sure if this is a clooge(using beginedit and endedit) or the stanard way of doing records with a dataset and saving them to the database.

Your help is really apppreciated...

Angela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top