DataBinding was "evil" in VB6.
What about in VB.NET?
Printable View
DataBinding was "evil" in VB6.
What about in VB.NET?
Generally thought to be a bad programming technique yeah.
YES and NO. Depends what you're after. If you need to build quick presentation app than I wouldn't say it's but if you intend to use such technic in your "real time" application then .. well you know ...
I hate it. Breeds laziness and lack of understanding of using databases. I hand code everything.
Ought we to differentiate between using the toolbox objects (connection, command, etc) and wizards (data form wizard) which are tools to facilitate databinding from actual databinding? I agree that using the former is lazy and often does result in not understanding DBs and, to a greater extent, how things really work, but is not synonymous with databinding. To use the simplest of examples, in .Net you can databind to arrays, enums, etc - hardly lazy and in no way representative of a lack of DB knowledge.Quote:
Originally posted by Cander
I hate it. Breeds laziness and lack of understanding of using databases. I hand code everything.
I think the real question here is in a customers form for ex., are you using two-way databinding and data adapters or manually setting fields and updating the DB.
Thoughts?
DataBinding sucks . :)
Pirate,
In previous versions of VB I would agree with you completely . . . DataBinding sucked immensely. In .NET, the same cannot be said. I have read several books and more than a hand full of articles on ADO.NET and in all cases, for quick displaying of data in say a DataGrid or a ListBox, DataBinding was the preferred method. With regard to controls like TextBoxes where you would potentially be updating the data, it is far better to manually populate the data in these controls and then intercept a KeyPress or Changed event to indicate that the data had changed and then write the appropriate code to submit your changes back to the source.
So it depends on what you are doing (Displaying vs Modifying) with your data as to what methodology is appropriate. :)
Databinding is against code reuse . I'm talking about complex databinding that involves that stupid databinding manager .
Ya'll can say whatever you want about databinding but me personally, I think its a godsend. :D
BTW I never ever use the databinding form wizard. I code everything by hand.
I'm glad that most here feel the way I felt when I read about it.
Now, here's the problem: A lot of the books out there are only teaching database access the databinding way. I'd really really appreciate it someone could point me to a link (perhaps a simple ADO.NET tutorial) where they teach databinding by hand.
OR, if someone could show me a sample that they may have made while learning ADO.NET.
There should be some sample on MSDN. When I first started doing .NET I never knew about databinding until I came here. I was hand coding everything for my data access.
Ok I akm firmly in the databinding camp. I tend to use it as a matter of course, yes you have problems with deicmal amd null values (especially dates) but they are easily overcome, someone asked for an example of databinding by hand (which I alwys use, here is an example:
VB Code:
' Bind Tenancies data to Windows form TextBox8.DataBindings.Add(New Binding("Text", ds2, "Tenancies.PropertyAdr")) NumTxtBox1.DataBindings.Add(New Binding("Text", ds2, "Tenancies.NoMonths")) CheckBox1.DataBindings.Add(New Binding("Checked", ds2, "Tenancies.LettingOnly")) TextBox9.Text = Format(dr2("ExpiresOn"), "dd MMMM yyyy") Dim b2 As Binding = New Binding("text", ds2, "Tenancies.Rent") AddHandler b2.Parse, AddressOf CurrDec AddHandler b2.Format, AddressOf DecCurr DecTxtBox1.DataBindings.Add(b2) ComboBox1.DataBindings.Add(New Binding("SelectedIndex", ds2, "Tenancies.PaymentFrequency")) Dim b5 As Binding = New Binding("text", ds2, "Tenancies.InitRent") AddHandler b5.Parse, AddressOf CurrDec AddHandler b5.Format, AddressOf DecCurr DecTxtBox2.DataBindings.Add(b5) Dim b3 As Binding = New Binding("text", ds2, "Tenancies.Bond") AddHandler b3.Parse, AddressOf CurrDec AddHandler b3.Format, AddressOf DecCurr DecTxtBox3.DataBindings.Add(b3) Dim b4 As Binding = New Binding("text", ds2, "Tenancies.Contribution") AddHandler b4.Parse, AddressOf CurrDec AddHandler b4.Format, AddressOf DecCurr DecTxtBox13.DataBindings.Add(b4) TextBox10.Text = Format(dr2("NextRentDue"), "dd MMMM yyyy") TextBox3.DataBindings.Add(New Binding("Text", ds2, "Tenancies.LeadTenant")) TextBox4.DataBindings.Add(New Binding("Text", ds2, "Tenancies.PhoneMobile")) TextBox5.DataBindings.Add(New Binding("Text", ds2, "Tenancies.PhoneWork")) TextBox6.DataBindings.Add(New Binding("Text", ds2, "Tenancies.EmergencyContact")) TextBox7.DataBindings.Add(New Binding("Text", ds2, "Tenancies.email")) ComboBox5.DataBindings.Add(New Binding("SelectedIndex", ds2, "Tenancies.PayMethod")) TextBox18.DataBindings.Add(New Binding("Text", ds2, "Tenancies.AccountName")) TextBox20.DataBindings.Add(New Binding("Text", ds2, "Tenancies.SortCode")) TextBox19.DataBindings.Add(New Binding("Text", ds2, "Tenancies.Account")) RichTextBox1.DataBindings.Add(New Binding("Text", ds2, "Tenancies.Notes")) Private Sub CurrDec(ByVal sender As Object, ByVal cevent As ConvertEventArgs) If Not cevent.DesiredType Is GetType(Decimal) Then Exit Sub End If cevent.Value = Decimal.Parse(cevent.Value.ToString, Globalization.NumberStyles.Currency, Nothing) End Sub Private Sub DecCurr(ByVal sender As Object, ByVal cevent As ConvertEventArgs) If Not cevent.DesiredType Is GetType(String) Then Exit Sub End If Try cevent.Value = CType(cevent.Value, Decimal).ToString("##,###0.00") Catch ' null value trap End Try End sub Private Sub DatStr(ByVal sender As Object, ByVal cevent As ConvertEventArgs) If Not cevent.DesiredType Is GetType(String) Then Exit Sub End If Try cevent.Value = CType(cevent.Value, Date).ToString("dd MMMM yyyy") Catch ' null value trap End Try End Sub Private Sub StrDat(ByVal sender As Object, ByVal cevent As ConvertEventArgs) If Not cevent.DesiredType Is GetType(Date) Then Exit Sub End If cevent.Value = Date.Parse(cevent.Value) End Sub
hope this helps rather than confuses
it confuses
Quote:
Originally Posted by mendhak
I thing that DataBinding is for Ms Access, why should we do Access in VB ... :afrog: :eek2:
I have heard it has worlds of improvement from the days of VB6, but since I come from the time when databinding was a NO-NO, I do everything by hand. It allows for the most amount of control between your classes and your database data
Designtime databinding: This is when you drop components onto a form in the designer, connect to a database, then set the datbindings right in the designer. This is bad (in my opin).
Runtime databinding: Where you create the databindings on the fly, when the app is running. Nice thing about this is that it doesn't have to be to a datatable or a dataset. I've used RT databindings to link my various controls to a dataclass. cuts down on the code & errors. This is OK, again, just my opin.
-tg
is there a performance hit in databinding versus code?
Add another one for thinking databinding evil in vb6 and in .net it looks the same but everything I've seen is databinding like drag n drop. I want to do it manually like we did in vb6.
hummm...strange...
databinding in an OOP language...????
give me a break...
Think of all the time saved on mundane stuff with the use of databinding, time that otherwise can go to the more complex parts of the program. I am a recent convert to databinding and used to think it was evil (and to some degree still do) but it is a good productivity tool. Keep in mind that it is a 'tool', one of many, I think it should be used where appropriate (including the IDE features that wire it up for you). I can't bring myself to use it as much as some in my office but I do now use it -generally for read only things. The best thing I like about it is I can bind to objects not just data.
I haven't used the tools in 2005 that much yet but it seems like it has DataBinding down to almost what it should be. The whole BindingSourceManager thing is kind of cool.
For everyone else here that knows of the databinding changes in 2005, Will they change your opinion of databinding?
NOTE: For some parts of an application or simple projects I would be questioned why I did NOT use databinding at my current job. I also would have to have a good reason why I took time to do it by hand instead of via the IDE. They view it as a cost thing and there is no way I could do it by hand as fast (for simple things).
This seems to be related here...