textbox databinding (which is better?)

thejeraldo

Well-known member
Joined
Jun 9, 2009
Messages
70
Location
Philippines
Programming Experience
1-3
uhm.. which is a better method to use in databinding?

textbox.text = dataset.tables(0).rows(0).item(0).tostring

or

textbox.databindings.add("text",dataset.tables(0)."employeename")

???

thanks...
 
Given that the first option isn't using data-binding at all, the only answer is the second option. Data-binding means that the value in the control and the value in the data source are bound together, i.e. whatever affects one will affect the other. That first code snippet is simply assigning a value manually. Any changes to either the control or the data source would require another manual assignment to update the other. Using the second option, i.e. data-binding, any changes you make to the data in the control will be automatically pushed back to the data source and vice versa.
 
The first is a bad way to do it in nearly all situations; it relies on position (which can change) and will crash if there is no data to be had at that position
 
In addition you may not need binding at all.
DataReader object will be probably more efficient for you.
Or even better (if you use MSSQL) .. OUTPUT parameter(s).
Just execute command and get the value of the parameter.

VB.NET:
Me.TextBox1.Text = command.Parameters("employeename").Value.ToString()
 
Just to elaborate on kulrom's post, data-binding would normally be used if the data was to be retrieved, displayed, edited and saved, especially if there were multiple records. If there's no editing and saving then you would probably still use data-binding if there were multiple records, although it would depend on the specific circumstances. If there's only one record to display with no editing then data-binding is a bit pointless.
 
uhmm.. do i need to have a binding if my method of saving an edited or new record is by means of an oledbcommand then executing an update/insert statement which is kinda like:

"UPDATE tblemp set EmpID='" + textbox1.text + "'" ??

or if you guys are saying that i dont need binding? then what do Pros like you use to show data from a record on a form??
 
uhmm.. do i need to have a binding if my method of saving an edited or new record is by means of an oledbcommand then executing an update/insert statement which is kinda like:

"UPDATE tblemp set EmpID='" + textbox1.text + "'" ??

or if you guys are saying that i dont need binding? then what do Pros like you use to show data from a record on a form??
If you've only got one record then I probably wouldn't use data-binding but if you have more than one then I would.
 
Back
Top