Refresh textbox.text with added row identity

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
I pass 3 variables to the form: icurrentShopNumber, icurrentPartID, and AddShopNumber. AddShopNumber number is boolean.

I load up the form with the current info needed from the Part and ShopNumber datasets and then check to see if we are adding a shopnumber record. If we are, a new datarow is added.
This all works.

I need the code to refresh the textbox displaying the ShopNumberID which is an autoincrement/identity field in the sql dataset. The record is added correctly, i can save it and go back to the grid form of the ShopNumber dataset and the record is correctly sequenced at the end.

How can i (refresh) the textbox.text to display the added ShopNumber when the form is opened?


the bindings for the textbox:

'editShop_Number
'
Me.editShop_Number.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsShopNumber21, "Shop Number.Shop Number"))
Me.editShop_Number.Location = New System.Drawing.Point(232, 16)
Me.editShop_Number.Name = "editShop_Number"
Me.editShop_Number.TabIndex = 32
Me.editShop_Number.Text = ""
'


the code for the form load:

PrivateSub frmShopNumber2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
SqlSelectCommand1.Parameters("@shopnum").Value = iCurrentShopNum
SqlSelectCommand2.Parameters("@partid").Value = iCurrentPartid
Me.LoadDataSet()
lblShopNum.Text = iCurrentShopNum.ToString
If addShopNumber = TrueThen
Try
Me.BindingContext(DsShopNumber21, "Shop Number").EndCurrentEdit()
Dim tblShopNum As DataTable
tblShopNum = DsShopNumber21.Tables("Shop Number")
Dim drCurrentSN As DataRowdrCurrentSN = tblShopNum.NewRow()Dim dt As DateTime = DateTime.NowdrCurrentSN("Part ID") = iCurrentPartid
drCurrentSN("date added") = dt.ToShortDateString
drCurrentSN("traveler") = editTraveler.CheckState = CheckState.Unchecked
drCurrentSN("open") = editOpen.CheckState = CheckState.Checked
drCurrentSN("shop class") = "shop"
tblShopNum.Rows.Add(drCurrentSN)
Catch eEndEdit As System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
EndTry
EndIf
EndSub


Thanks,
David
 
DataSet1.AcceptChanges does refreshing for bound controls, but you should do it after you've updated the database : DataAdapter.Update(DataSet1, "TABLE") yada yada....
 
AcceptChanges is called - no refresh occurs

I call the AcceptChanges function in the UpdateDataSet method,

Public Sub UpdateDataSet()
Dim objDataSetChanges As Mack.dsShopNumber2 = New Mack.dsShopNumber2
Me.BindingContext(DsShopNumber21, "Shop Number").EndCurrentEdit()
objDataSetChanges = CType(DsShopNumber21.GetChanges, Mack.dsShopNumber2)
If (Not (objDataSetChanges) Is Nothing) Then
Try
Me.UpdateDataSource(objDataSetChanges)
DsShopNumber21.Merge(objDataSetChanges)
DsShopNumber21.AcceptChanges()
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If
End Sub

For some reason the databound control for the autoincrement/identity field is not refreshed until the page is closed and reopened. The other factor is that I don't know the value of the autoincrement ShopNumber right after it is added (when the form is displayed). Since I don't have the value (icurrentShopNumber) I have no way to pass it to the sql statement and reload the dataset with the added record.

The only field effected is the autoincrement/identity field. All other fields start with the added values. ShopNumber starts with a value of 0 in the textbox.

Thanks for looking,
David
 
Back
Top