|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Any idea why my BindingSource won't update?1 x .NET 2.0 .DLL Containing one public DataSet (CustomerHandler) which contains one table and a tableadapter to fill a datatable 1 x .NET 2.0 EXE With a single form containing a DataSet (CustomerHandler1), a BindingSource and a BindingNavigator. And also a whole load of textbox controls which are databound to the BindingSource. 1 x SQL Server Express database -- The problem is this: When I enter the form, it reads the data perfectly and I can move from record to record vis the BindingNavigator, and even add, delete and update records. However, these changes are not being carried through to the database - I ran SQL Server Profiler on the database and nothing was happening at any stage, not even when the .EndEdit() method was called. I am assuming that because I have a DataSet (CustomerHandler1) on my form, that it is this that is being changed, and not the dataset in the satellite assembly. I want all my data in the satellite assembly as this is my data access layer (DAL). The code is as follows (CustomerHandler is the name of my dataset as defined in the satellite assembly): Dim CustomerHandlerTA As New CustomerHandlerTableAdapters.II_CUSTOMERTableAdapter Try CustomerHandlerTA = New CustomerHandlerTableAdapters.II_CUSTOMERTableAdapter CustomerHandlerTA.Fill(CustomerHandler1.II_CUSTOMER) Catch ex As Exception MsgBox(ex.Message) Finally CustomerHandlerTA = Nothing End Try Private Sub SaveChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveChanges.Click BindingSource.EndEdit() End Sub -- It all works perfectly in read-only mode and the dataset can be edited in memory, but why aren't changes being propogated through to the database? Any suggestions very warmly welcome! Mike "Mike" <none> wrote in message news:eQL$i$zEGHA.1396@TK2MSFTNGP11.phx.gbl... Ok, I've fixed it - but my fix is just a hack. Basically, I can't call a tableadapter update and pass in a dataset - I have to explicitally pass in a datatable - this works. I can't access the TableAdapter that I create below because it's out of scope in the SaveChanges_Click(..) function. So... I moved the CustomerHandlerTA declaration and made it a friend variable at the top of the module. Messy, is there a better way? I also changed the SaveChanges_Click() such that I now call: CustomerHandlerTA.Update(CustomerHandler1.II_CUSTOMER) Again, messy. I'd rather call the BindingSource.EndEdit() method. Why doesn't this method simply work on its own? -- My next problem is I need to add more datatables to the dataset. How can I go about updating an entire dataset in one go? One would have thought the ..EndEdit() method called on a BindingSource bound to a DataSet would work fine. If I create a DataTable which contained a SQL set of data from across multiple tables, could I still insert new rows in this way? One would think not, as the META-data describing the relationships between the various original tables will have been lost in translation. Thanks in advance for any advice! Warm Regards, Mike |
|||||||||||||||||||||||