Adding Records to a Record set

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Windows form with a number of Bound Controls. When I want to add a new record I clear all the combo boxes and text boxes by setting the text properties to "". To add a new record to the dataset I use

Dim drNew As System.Data.DataRo
drNew = Me.DsEstablishMaint1.Establishments.NewRo
With drNe
.Item("Code") = txtEstCode.Tex
.Item("Name") = txtName.Tex
.Item("Street") = txtAddress1.Tex
e.t.c
End Wit
DsEstablishMaint1.Establishments.AddEstablishmentsRow(drNew

The problem I have got is that I have a bound Combobox at the top of my form to select a record based on name. After adding a new record the name on the record I have just entered appears twice: once in the correct alphabetical position and once at the end of the list. If I try and select any name in the list my program crashes with "Duplicate values are not allowed on name" which is my primary key. I have tried experimenting with Currency Manager's AddNew() method but this created further problems. So is there a way to prevent the duplicate values appearing in my combo box and why should this happen anyway?
 
Hi Geoff,

An advice never type recordset in your subject, mostly that are unanswered
questions here.

More because you use a dataset.

Try to set a dataview between it.
dv = new dataview(dsEstablishment1.establishments)
dv.sort = "Name" 'or whatever
cb.datasource = dv

Then it will me showup sorted.

Because this was your first problem I do not know if the next will stay?

Cor

I have a Windows form with a number of Bound Controls. When I want to add
a new record I clear all the combo boxes and text boxes by setting the text
properties to "". To add a new record to the dataset I use:
Dim drNew As System.Data.DataRow
drNew = Me.DsEstablishMaint1.Establishments.NewRow
With drNew
.Item("Code") = txtEstCode.Text
.Item("Name") = txtName.Text
.Item("Street") = txtAddress1.Text
e.t.c.
End With
DsEstablishMaint1.Establishments.AddEstablishmentsRow(drNew)

The problem I have got is that I have a bound Combobox at the top of my
form to select a record based on name. After adding a new record the name
on the record I have just entered appears twice: once in the correct
alphabetical position and once at the end of the list. If I try and select
any name in the list my program crashes with "Duplicate values are not
allowed on name" which is my primary key. I have tried experimenting with
Currency Manager's AddNew() method but this created further problems. So is
there a way to prevent the duplicate values appearing in my combo box and
why should this happen anyway?
 
Geoff:

Is there anything else happening, perhaps behind SelectedItem changed or
anything like that. I used your exact code and it just adds it once at the
end. Also, do you have it sorted or anything?
Geoff Murley said:
I have a Windows form with a number of Bound Controls. When I want to add
a new record I clear all the combo boxes and text boxes by setting the text
properties to "". To add a new record to the dataset I use:
Dim drNew As System.Data.DataRow
drNew = Me.DsEstablishMaint1.Establishments.NewRow
With drNew
.Item("Code") = txtEstCode.Text
.Item("Name") = txtName.Text
.Item("Street") = txtAddress1.Text
e.t.c.
End With
DsEstablishMaint1.Establishments.AddEstablishmentsRow(drNew)

The problem I have got is that I have a bound Combobox at the top of my
form to select a record based on name. After adding a new record the name
on the record I have just entered appears twice: once in the correct
alphabetical position and once at the end of the list. If I try and select
any name in the list my program crashes with "Duplicate values are not
allowed on name" which is my primary key. I have tried experimenting with
Currency Manager's AddNew() method but this created further problems. So is
there a way to prevent the duplicate values appearing in my combo box and
why should this happen anyway?
 
Thanks for your suggestions. I think my problems were caused by having a text box and a combo box bound to the same database field. I have also added a Dataview sorted on my name field. So everyting is working as it should now

Thanks again.
 
Back
Top