Hi All,
I am hoping that someone is able to help me with something simple.
I am working with a bound form.
The binding works as far as loading and editing data and then saving to the database.
However, when adding a new record it is not working...
It has one text box where the record results are shown in a listbox.
Event Firing:
1) OnLoad the binding is set up
Me.txt_Type.DataBindings.Add(New System.Windows.Forms.Binding("Text", dsInfo, "Types.Title"))
2) Some clicks the "add" button I set the:
Me.BindingContext(dsInfo, "types").AddNew()
bAdding = True
3) Someone Types "Test Type" in the text box
4) Someone Clicks the Save Button. I do the following:
Private Sub saveAddition()
If (checkValue(Me.txt_Type.Text) = "") Then
'If add is clicked and nothing typed then do not save
Me.BindingContext(dsInfo, "types").CancelCurrentEdit()
Else
'if added and there is a value save it
sqlAdapter.Update(dsInfo, "Types")
dsInfo.AcceptChanges()
End If
End Sub
It will not appear in the list box I have showing all the records in the dataset and won't save to the database...
The only way I can get it to save to the database and dataset by doing this and dealing with the dataset directly:
Dim dRow As DataRow
dRow = dsInfo.Tables("types").NewRow
dRow("Title") = Me.txt_Type.Text
dsInfo.Tables("types").Rows.Add(dRow)
However, this ONLY works if I am unbound to the dataset with the text field.
Unfortunately, I can not see any solution to getting the addnew binding to work.
I see a solution that allows me to use a mix of binding and not binding. But it looks like a clooge and I am thinking I must be doing something wrong:
1) When Adding New. Add a Blank row to the Dataset. Do
NOT use .addnew in the bindingcontext
2) When saving check for value if no value then delete
blank row added or was place each individual field
into the dataset row and the flush changes to the
database.
Is that standard way to get this to work in a binded mode?
Or I am missing something simple with the addnew binding?
I honestly thought Binding was suppose to make this stuff simpler to work with. Like using Access. You know instead of saving each individual record with its fields each time manually like you have to do with web programming or back in the good old days. You can set up your data store and with a few lines of code tell it to save or add.
I hope this makes sense...Am I doing this wrong or is vb.net just not all that when it comes to handling bounded data?
Many thanks!
Angela
PS I am use to all or nothing I program with ASP.NET, ASP, and Access Database. Just to give you a reference of what I have worked with over the years (I won't mention my early career of programming with flat priortory file systems
)
I am hoping that someone is able to help me with something simple.
I am working with a bound form.
The binding works as far as loading and editing data and then saving to the database.
However, when adding a new record it is not working...
It has one text box where the record results are shown in a listbox.
Event Firing:
1) OnLoad the binding is set up
Me.txt_Type.DataBindings.Add(New System.Windows.Forms.Binding("Text", dsInfo, "Types.Title"))
2) Some clicks the "add" button I set the:
Me.BindingContext(dsInfo, "types").AddNew()
bAdding = True
3) Someone Types "Test Type" in the text box
4) Someone Clicks the Save Button. I do the following:
Private Sub saveAddition()
If (checkValue(Me.txt_Type.Text) = "") Then
'If add is clicked and nothing typed then do not save
Me.BindingContext(dsInfo, "types").CancelCurrentEdit()
Else
'if added and there is a value save it
sqlAdapter.Update(dsInfo, "Types")
dsInfo.AcceptChanges()
End If
End Sub
It will not appear in the list box I have showing all the records in the dataset and won't save to the database...
The only way I can get it to save to the database and dataset by doing this and dealing with the dataset directly:
Dim dRow As DataRow
dRow = dsInfo.Tables("types").NewRow
dRow("Title") = Me.txt_Type.Text
dsInfo.Tables("types").Rows.Add(dRow)
However, this ONLY works if I am unbound to the dataset with the text field.
Unfortunately, I can not see any solution to getting the addnew binding to work.
I see a solution that allows me to use a mix of binding and not binding. But it looks like a clooge and I am thinking I must be doing something wrong:
1) When Adding New. Add a Blank row to the Dataset. Do
NOT use .addnew in the bindingcontext
2) When saving check for value if no value then delete
blank row added or was place each individual field
into the dataset row and the flush changes to the
database.
Is that standard way to get this to work in a binded mode?
Or I am missing something simple with the addnew binding?
I honestly thought Binding was suppose to make this stuff simpler to work with. Like using Access. You know instead of saving each individual record with its fields each time manually like you have to do with web programming or back in the good old days. You can set up your data store and with a few lines of code tell it to save or add.
I hope this makes sense...Am I doing this wrong or is vb.net just not all that when it comes to handling bounded data?
Many thanks!
Angela
PS I am use to all or nothing I program with ASP.NET, ASP, and Access Database. Just to give you a reference of what I have worked with over the years (I won't mention my early career of programming with flat priortory file systems