Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

databinding .AddNew() problem

Status
Not open for further replies.

Guern

Programmer
Jun 22, 2001
91
GB
hello,

Can somone help me out with .AddNew() and an acecss db?

So far I have several fields bound to an access database with 1 unique autoincrement field (ID). I can navigate the recordset and update records without problem. My question is about the adding of records.

So far I have a button that runs (when you click this there is a short delay)

Me.BindingContext(dsEmployee, "employee").EndCurrentEdit()
Me.BindingContext(dsEmployee, "employee").AddNew()

I don't clear the fields and the existing data stays there. The record count appears to increase. I make some changes then

Me.BindingContext(dsEmployee, "employee").EndCurrentEdit()
odaEmployee.Update(dsEmployee, "employee")

The record only seems to update an existing record. If I close the window and go back to reload the ds, no new record. If I go mad and press add several times and then save, I get a few blank records at the end.

Can somone give me the right way of doing this?

Thanks.
 
After a few days rest, I've figured out what is causing the problems, though I still don't have a solution.

I have several check boxes and a couple of radio buttons. If I unbind them from the data source I can add records instantly.

So, what's the secret? Can you bind a checkbox to a datasource/access database? Please share! :)
 
Finally sorted this. Found this on another site.


basically Me.BindingContext will not allow Null values to be added to a boolean item.

hence rather than using


Code:
Me.BindingContext(objProducts, "Products").AddNew()


it should be replaced with


Code:

Dim dr As DataRow
dr = objProducts.Tables("Products").NewRow
dr.Item("ProductName") = ""
dr.Item("Discontinued") = False
' Set any other fields that cannot null to default values.
objProducts.Tables("Products").Rows.Add(dr)
' then move to last record

Hope this helps someone else. Drove me bonkers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top