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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newrow in a dataset bound to a textbox 1

Status
Not open for further replies.

blink416

Technical User
Mar 22, 2005
20
GB
I have a textbox bound to a dataset filled by an OleDB adapter. I can navigate through the records in the GUI (Me.BindingContext(DataSetContact, "Contact").Position += 1 etc) but have been unable to add a new row to the dataset (and database). What code could I use to allow the user to click on say a command button "New" and then type the information to be inserted in the database to the textbox ? ( relevant code suggestions from MSDN doesn't seem to function though I may have got smth wrong )
 
I believe this should work unless your DataSet has constraints that require you to fill in more data or some of your controls won't take well to nulls AND you have not defined defaults.

CType(Me.BindingContext(DataSetContact, "Contact"), CurrencyManager).AddNew()
 
Thanks !!! It turns out there was a problem with a default value, so I hopefully solved it like this. Strangely enough it did actually write to the database before but wouldnt show any records beyond the one missing a DateOfBirth value, so navigation became affected as well.

Dim myRow As DataRow
myRow = DataSetContact.Tables("Contact").NewRow()
myRow("DateOfBirth") = "01.01.1999"
DataSetContact.Tables("Contact").Rows.Add(myRow)
ContactCount = Me.BindingContext(DataSetContact, "Contact").Count
Me.BindingContext(DataSetContact, "Contact").Position = ContactCount - 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top