florin Posted April 25, 2005 Posted April 25, 2005 Hello. I am a .net nevby. I try to update rows in a Postgresql Database, from a application written in VB .NET. I have some textboxes on my window form, bound to a DataSet via a Databinding: Me.lbId().DataBindings.Add(New Binding("Text", dsPupil, "esantion.Id")) Me.txtNrMat().DataBindings.Add(New Binding("Text", dsPupil, "esantion.nrmat")) Me.txtDen().DataBindings.Add(New Binding("Text", dsPupil, "esantion.denumire")) Me.txtEra().DataBindings.Add(New Binding("Text", dsPupil, "esantion.era")) Me.txtImage().DataBindings.Add(New Binding("Text", dsPupil, "esantion.image")) Me.txtLocalizare().DataBindings.Add(New Binding("Text", dsPupil, "esantion.localizare")) Me.txtIncadrare().DataBindings.Add(New Binding("Text", dsPupil, "esantion.loc")) Then I try to change the values in these Textboxes, and hit the Save Button. Here is the Event Handler for my Save Button: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click BindingContext(dsPupil, "esantion").EndCurrentEdit() Dim m As MData = New MData m.SaveData(dsPupil, "esantion") 'call LoadData on main form to refresh grid MsgBox("S-a salvat esantionul!!") Me.BringToFront() Me.LoadData(Me.dsPupil) End Sub And this is the procedure in the class MData that is supposed to do the job: Public Sub SaveData(ByVal ds As DataSet, ByVal table As String) 'Update a dataset representing pupils Dim conn As CoreLab.PostgreSql.PgSqlConnection = GetConnection() Try Dim sql As String = "Select * from " + table MsgBox(sql) Dim da As CoreLab.PostgreSql.PgSqlDataAdapter = New CoreLab.PostgreSql.PgSqlDataAdapter(sql, conn) Try Dim cb As CoreLab.PostgreSql.PgSqlCommandBuilder = New CoreLab.PostgreSql.PgSqlCommandBuilder(da) If ds.HasChanges Then Try da.Update(ds, table) ds.AcceptChanges() Catch es As Exception MsgBox("Nu s-a putut face modificarea!!", es.Message, es.Source) Finally End Try End If Finally da.Dispose() End Try Finally conn.Close() conn.Dispose() End Try End Sub The curios thig is: it worked before I added the Databinding -> txtIncadrare to esantion.loc. Now I get teh Currency error, when trying to do the update. I would aprechiate it,if somewone could help me out with this! Quote
HJB417 Posted April 26, 2005 Posted April 26, 2005 I don't think you need to invoke AcceptChanges after invoking Update, but that's probably not going to stop the error that's being generated. Quote
florin Posted April 26, 2005 Author Posted April 26, 2005 I removed the ds.AcceptChanges() but it still doesn't work. The problem appears to be that I used the Me.txtId().DataBindings.Add(New Binding("Text", dsPupil, "table.id")) method 7 times. When I used it 6 times on a table containig 6 colums it worked. As soon as I added one more row and one more textField on the form, and then used the DataBindings Method for that TextField it stopped working. I am really stuck here... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.