vb.net:
Hey everyone... I have what I hope is a simple question. I have a form with about a dozen controls bound to a databinding source. That datasource is bound to a dataset. Without using a binding navigator, how do I do anything with this thing?? I can't for the life of me figure out how to add, update, etc... Is this possible without the navigator? Thanks!!
Hello, BindingSource component provide some method to add, update records, for example, to add a record, call AddNew() method; to update, call EndEdit() method; to remove a record, call remove() mthod. All these can be done without a navigator. Hope this help, Luke Zhang (This posting is provided "AS IS", with no warranties, and confers no rights.)
When I try to make this work I run into a problem. I call addnew and then should be able to call endedit. However, when I do that I keep getting an error kicked back about null values for columns. This happens with or without data in my columns. Why is it its not recognizing the values I put in my text boxes?? Does this make sense? As an example... If I have a text box called Key and I put something in it I get a null reference error. But, if after calling AddNew I set the value of my textbox via code then it recognizes that value. It seems like maybe I broke something with my databinding but it half way works ... [quoted text, click to view] "Luke Zhang [MSFT]" <lukezhan@online.microsoft.com> wrote in message news:$4LuCVNPGHA.616@TK2MSFTNGXA03.phx.gbl... > Hello, > > BindingSource component provide some method to add, update records, for > example, to add a record, call AddNew() method; to update, call EndEdit() > method; to remove a record, call remove() mthod. All these can be done > without a navigator. > > Hope this help, > > Luke Zhang > (This posting is provided "AS IS", with no warranties, and confers no > rights.) >
I think my problem was the lack of the CurrencyManager. I don't have one of those anywhere ... Thanks for the quick reply, I'm off to explore. [quoted text, click to view] "Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message news:eIzWUNWPGHA.3944@tk2msftngp13.phx.gbl... > Andrew, > > Was it you that I showed yesterday this sample on our website? > > http://www.vb-tips.com/default.aspx?ID=c6c7d9a8-7511-41a1-a488-2e91e5295e7c > > Otherwise I hope this helps, > > Cor > > > "Andrew Bassett" <Flesrouy@community.nospam> schreef in bericht > news:O8NpW7VPGHA.3196@TK2MSFTNGP09.phx.gbl... >> When I try to make this work I run into a problem. I call addnew and then >> should be able to call endedit. However, when I do that I keep getting an >> error kicked back about null values for columns. This happens with or >> without data in my columns. Why is it its not recognizing the values I >> put in my text boxes?? Does this make sense? As an example... >> >> If I have a text box called Key and I put something in it I get a null >> reference error. But, if after calling AddNew I set the value of my >> textbox via code then it recognizes that value. >> >> It seems like maybe I broke something with my databinding but it half way >> works ... >> >> >> "Luke Zhang [MSFT]" <lukezhan@online.microsoft.com> wrote in message >> news:$4LuCVNPGHA.616@TK2MSFTNGXA03.phx.gbl... >>> Hello, >>> >>> BindingSource component provide some method to add, update records, for >>> example, to add a record, call AddNew() method; to update, call >>> EndEdit() >>> method; to remove a record, call remove() mthod. All these can be done >>> without a navigator. >>> >>> Hope this help, >>> >>> Luke Zhang >>> (This posting is provided "AS IS", with no warranties, and confers no >>> rights.) >>> >> >> > >
On your example you have the following line.... cma =3D DirectCast(BindingContext(dt), CurrencyManager) I'm having trouble making that work. If I try this... cma =3D DirectCast(Me.Sites_MBindingSource, CurrencyManager) I get an error stating I cannot convert a binding source to a Currency = Manager. How can I make that work? [quoted text, click to view] "Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message = news:eIzWUNWPGHA.3944@tk2msftngp13.phx.gbl... > Andrew, >=20 > Was it you that I showed yesterday this sample on our website? >=20 > =
http://www.vb-tips.com/default.aspx?ID=3Dc6c7d9a8-7511-41a1-a488-2e91e529= 5e7c [quoted text, click to view] >=20 > Otherwise I hope this helps, >=20 > Cor >=20 >=20 > "Andrew Bassett" <Flesrouy@community.nospam> schreef in bericht=20 > news:O8NpW7VPGHA.3196@TK2MSFTNGP09.phx.gbl... >> When I try to make this work I run into a problem. I call addnew and = then=20 >> should be able to call endedit. However, when I do that I keep = getting an=20 >> error kicked back about null values for columns. This happens with or = >> without data in my columns. Why is it its not recognizing the values = I put=20 >> in my text boxes?? Does this make sense? As an example... >> >> If I have a text box called Key and I put something in it I get a = null=20 >> reference error. But, if after calling AddNew I set the value of my=20 >> textbox via code then it recognizes that value. >> >> It seems like maybe I broke something with my databinding but it half = way=20 >> works ... >> >> >> "Luke Zhang [MSFT]" <lukezhan@online.microsoft.com> wrote in message=20 >> news:$4LuCVNPGHA.616@TK2MSFTNGXA03.phx.gbl... >>> Hello, >>> >>> BindingSource component provide some method to add, update records, = for >>> example, to add a record, call AddNew() method; to update, call = EndEdit() >>> method; to remove a record, call remove() mthod. All these can be = done >>> without a navigator. >>> >>> Hope this help, >>> >>> Luke Zhang >>> (This posting is provided "AS IS", with no warranties, and confers = no >>> rights.) >>> >> >>=20 >=20
Andrew, Was it you that I showed yesterday this sample on our website? http://www.vb-tips.com/default.aspx?ID=c6c7d9a8-7511-41a1-a488-2e91e5295e7c Otherwise I hope this helps, Cor "Andrew Bassett" <Flesrouy@community.nospam> schreef in bericht news:O8NpW7VPGHA.3196@TK2MSFTNGP09.phx.gbl... [quoted text, click to view] > When I try to make this work I run into a problem. I call addnew and then > should be able to call endedit. However, when I do that I keep getting an > error kicked back about null values for columns. This happens with or > without data in my columns. Why is it its not recognizing the values I put > in my text boxes?? Does this make sense? As an example... > > If I have a text box called Key and I put something in it I get a null > reference error. But, if after calling AddNew I set the value of my > textbox via code then it recognizes that value. > > It seems like maybe I broke something with my databinding but it half way > works ... > > > "Luke Zhang [MSFT]" <lukezhan@online.microsoft.com> wrote in message > news:$4LuCVNPGHA.616@TK2MSFTNGXA03.phx.gbl... >> Hello, >> >> BindingSource component provide some method to add, update records, for >> example, to add a record, call AddNew() method; to update, call EndEdit() >> method; to remove a record, call remove() mthod. All these can be done >> without a navigator. >> >> Hope this help, >> >> Luke Zhang >> (This posting is provided "AS IS", with no warranties, and confers no >> rights.) >> > >
In my test, after call Addnew, the TextBox is changed to blank and I can type some string in it. Then I click a button to call bindingSource1.EndEdit() and this work. Are all of the fileds in bindingSource bound to a control on the form? Before EndEdit(), is each of these controls has a actual value? When you get the exception like Column 'abc' does not allow nulls. You may check if the field 'abc' is bound to a control (for example, a TextBox) and if it has a actual value Luke Zhang (This posting is provided "AS IS", with no warranties, and confers no rights.)
You can do same thing without Navigator by using – 'Moves data item First Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click Me.BindingContext(DA, "Employee").Position = 0 End Sub 'Moves data item Last Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click Me.BindingContext(DA, "Employee").Position = Me.BindingContext(DA, "Employee").Count - 1 End Sub 'Moves data item Next Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveNext.Click Me.BindingContext(DA, "Employee").Position -= 1 End Sub 'Moves data item Prev Private Sub btnMovePrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMovePrev.Click Me.BindingContext(DA, "Employee").Position += 1 End Sub 'Add New item Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click Dim instance As BindingNavigator Dim value As ToolStripItem value = instance.AddNewItem instance.AddNewItem = value End Sub 'Delete item Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click Dim instance As BindingNavigator Dim value As ToolStripItem value = instance.DeleteItem instance.DeleteItem = value End Sub
You can do the same without Navigator by using – 'Moves data item First Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click Me.BindingContext(DA, "TBL").Position = 0 End Sub 'Moves data item Last Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click Me.BindingContext(DA, "TBL").Position = _ Me.BindingContext(DA,"TBL").Count - 1 End Sub 'Moves data item Next Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveNext.Click Me.BindingContext(DA, "TBL").Position -= 1 End Sub 'Moves data item Prev Private Sub btnMovePrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMovePrev.Click Me.BindingContext(DA, "Employee").Position += 1 End Sub 'Add New item Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click Dim instance As BindingNavigator Dim value As ToolStripItem value = instance.AddNewItem instance.AddNewItem = value End Sub 'Delete item Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click Dim instance As BindingNavigator Dim value As ToolStripItem value = instance.DeleteItem instance.DeleteItem = value End Sub As an alternative download IdeaBlade’s DevForce Express and use that for ORM (I don’t work for them – but use it extensively)
Don't see what you're looking for? Try a search.
|