update issues using tableadapters and dataadapters
Hi,
Can you interchangeable use tableadapters and dataadapters? I am writing in .net (2005) with a sqlite db(v3). I need to display rtf files inside an rtf box. In order to do that, binding to a datasource is not possible. So on the form where I display the rtf file, I load the data from the database via a dataadapter. Everywhere else I use tableadapters. On the form where I have the rtf box, the changes look fine but on the previous form, the changes are not visible. Do I have two separate copies of the database in two different datasets?
To be more specific:
first form gathers info from user, fields populated with table adapter, then updated after user makes changes
Me.Validate()Me.Personalize_infoBindingSource.EndEdit()Me.Personalize_infoTableAdapter.Update(Me.BenefitData.personalize_info)using this information, data is read into a dataset via dataadapter then inserted into empty table via tableadapter
Dim ConnStrAsString ="Data Source=name.db;Version=3;"Dim queryStringAsString = _"SELECT deletable, single_column, page_break, fill_blanks, page_content_id, " & _"page_id, required, editable, title, copy " & _" FROM pages_content WHERE state_id = 0"' Open and fill a DataSet.Dim adapterAs DataAdapter =New DataAdapter( _queryString, ConnStr)
Dim policiesAsNew DataSetadapter.Fill(policies,
"Pages_content")' Create a SqlDataReader for use with the Load Method.Dim readerAs DataTableReader = policies.CreateDataReader()' Create an instance of DataTable and assign the first' DataTable in the DataSet.Tables collection to it.Dim dataTableEmpAs DataTable = policies.Tables(0)' Fill the DataTable with data by calling Load and' passing the DataReader.dataTableEmp.Load(reader, LoadOption.Upsert)
Dim policyRowAs DataRow'insert default policiesForEach policyRowIn dataTableEmp.RowsMe.Personalize_pagesTableAdapter.Insert(CType(policyRow("deletable"),Decimal), _0,
CType(policyRow("single_column"),Decimal), 0,CType(policyRow("page_break"),Decimal), _0,
"",CType(policyRow("fill_blanks"),Decimal), 0,CType(policyRow("page_content_id"),Decimal), _myID,
CType(policyRow("page_id"),Long), 0,CType(policyRow("required"),Long),CType(policyRow("editable"),Long), _0,
CType(policyRow("title"),String),CType(policyRow("copy"),String),"")Next policyRowTry'get the data into the datatable and save to databaseMe.Validate()Me.personalize_pagesBindingSource.EndEdit()Me.Personalize_pagesTableAdapter.Update(Me.myData.personalize_pages)Me.MyData.AcceptChanges()Catch exAs ExceptionMsgBox(
"update failed")EndTryall of this works fine.
Then another form is opened that uses a tableadapter to move through the newly created table (personalize_pages).
Certain labels and coloring are based on boolean fields. This form has a button which will bring up a third form containing the rtf file the user may edit. This form seems to work fine.
3rd form displays an rtf box, filling data via a dataadapter. boolean values are set based on what the user does, then the database is updated, this form is closed and the second form opens up again.
This is the problem. the 2nd and 3rd forms do not reflect the same data. The third form may update and reflect those changes but the second form does not see the boolean field that says the rtf file has been edited. There is also a button on the 2nd form which prints the rtf file. This is filled via dataadapter and it reflects the same changes as seen on the 3rd form.
Maybe I need to use the data adapter for all the data in the 2nd form? How do you movenext and moveprevious with a data adapater?
anyway - here is the udpate code for the 3rd form.
Dim cnAsNew Connection()Dim PolicyDataSetAsNew DataSet()Dim daPolicyAs DataAdapterDim cmdBuilderAs CommandBuilderDim SelectStringAsString = _"SELECT deletable, blanks_filled, single_column, group_use, " & _"page_break, viewed, blanks, fill_blanks, personalized, page_content_id, id, " & _"page_id, page_order, required, editable, use, title, copy, title_class " & _" FROM personalize_pages WHERE page_content_id = """ & txtPageContentID.Text &""""'Set the connection stringcn.ConnectionString =
"Data Source=name.db;Version=3;"cn.Open()
'Initialize the DataAdapter objectdaPolicy =
DataAdapter(SelectString, cn)'Initialize the SqlCommandBuilder object to automatically generate and initialize'the UpdateCommand, InsertCommand and DeleteCommand properties of the SqlDataAdapter.cmdBuilder =
New CommandBuilder(daPolicy)'Populate the dataset by running the Fill method of the DataAdapter.daPolicy.Fill(PolicyDataSet,
"personalize_pages")'Modify the valuesPolicyDataSet.Tables(
"personalize_pages").Rows(0)("Title") = txtTitle.TextPolicyDataSet.Tables(
"personalize_pages").Rows(0)("Copy") = rtfCopy.RtfPolicyDataSet.Tables(
"personalize_pages").Rows(0)("personalized") = txtPersonalized.TextPolicyDataSet.Tables(
"personalize_pages").Rows(0)("viewed") = chkViewed.Checked'Post the data modification to the database.daPolicy.AcceptChangesDuringUpdate =
TruedaPolicy.Update(PolicyDataSet,
"personalize_pages")myData.AcceptChanges()
'Close the database connection.cn.Close()
Do table adapters open and close connections or do I need to do that?
Sorry this is so long but can anyone tell what I am doing wrong?
Thanks!

