Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...