dumb database question


VB.NET Forum Moderator
Staff member
Jun 3, 2004
Lansing, MI; USA
Programming Experience
ok, i've got a simple two table ms access database, most of the primary table is displayed in labels but some parts of it (three feilds actually) contain balances of which are calculated by the program, instead of binding them to labels or textboxs i want them to be stored in variables, how do i do this? and when i update the dataset, those variable values go back to the database as well, how do i do that too?
pretty much i jes want to bind a variable to a feild in a database like you would a label or a textbox is all
Yeah, I would also like to know. Dumb question, but valid, none-the-less.
Since you didn't specify, I assume you're using a dataTable to hold the data from the dataBase :).

If so, you can create a new dataColumn, set it's Expression property to a valid expression, and add the column to the dataTable. Then you could bind the text property of a textbox or label to the new column. You can also Update the dataBase with the new dataSet.

Here's sample code for creating the new column. The example dataTable has two columns (fields) named Number1 and Number2. The new column is the addition of these two fields. The dataTable is named dt and the textbox that is bound to the new column is named txtAddition.
Dim dc As DataColumn
dc = New DataColumn("Addition", GetType(System.Int32))
dc.Expression = "Number1 + Number2"
txtAddition.DataBindings.Add(New Binding("Text", dt, "Addition"))

Please try to use more descriptive subject lines. Thanks :).