how to bind data to textbox from dataset?

R

Rich

Hello,

I have successfully created an oledbconnection (oleconn)
to an Access mdb file along with an oleaDBdapter (oleda)
and a dataset (ds1). If I loop through the dataset

For i = 1 to 10
For Each col in ds1.Tables(0).Columns...
Console.Write col....(0,i), ...(1,i)...(2,i)
Next
next

I get data for the whole table. I defined the table name
from Access (tbl1) as dtTbl1, and each of 3 fields (fld1,
fld2, fld3) as dcfld1, dcfld2, dcfld3 in the dataset
object. Now I have 3 textboxes on a form, txt1, txt2,
txt3. When I bind these controls to the dataset I see ds1
in the Databindings Property. When I expand ds1 I see
tbl1 (not dtTbl1) and then when I expand tbl1 I see
fld1... (and not dcfld1...). So I select fld1 and press
Enter and for txt2, txt3. (Note: I do see dtTbl1 in the
Databindings property just below ds1. I tried selecting
that and the fields dcfld1..., but that did not yield
anything either).

So on the Form Load event I have
ds1.Clear()
oleda.Fill(ds1, "tlb1")

But when the form loads I do not see any data in my
textboxes. Obviously I am missing something. I mean,
yeah, I could programmatically populate each textbox, but
I need to do it through the Databindings. I would be very
appreciative if someone could tell me what else I need to
do for data to show up in my textboxes with databinding.
Then I could take it from there to cycle through the rows
of the dataset.

Thanks in advance,
Rich
 
C

Cor

Hi Rich,

Have a look at the "currencymanager",

If you do not succeed send a message tomorrow, than I can see how I can help
you with some samples.

Or maybe someone else is sending you that here.

Cor
 
R

Rich

Thanks. I don't have dotnet here (at the workplace), so I
have to wait till I get home tonight (taking a class in
dotnet). May I ask what the currencymanager is? Is this
a property in the textbox, form?
 
R

Rich

OK. I figured out what the CurrencyManager is (from the
textbook). Lets see if this is correct:

Me.BindingContext(ds1, "tbl1").Position = 0 'for 1st rec

Man, I guess there is no substitution for reading the
book. Well, the suggestion to look up the CurrencyManager
really helped. Did I do it correctly (above code)?

Thanks very much.
 
C

Cor

Hi Rich,

Currencymanager is a part of the binding you bind to your dataset
You bind the fields from your datatables than to the textboxes (text) and
with the position in the currencymanager you fill automaticly the textboxes
(and visa versa)

It looks difficult but when you have done it, it is imple

I hope this helps,

Cor
 
R

Rich

Try this after setting the bindings in the Databindings
property for each textbox (this sets the CurrencyManager):

'for 1st rec
Me.BindingContext(dataset1, "Table1").Position = 0
 
C

Cor

Hi Sarah and also for Rich,

\\\
dim cma As CurrencyManager
cma = CType(BindingContext(dataset1.Tables(0)), CurrencyManager)
textbox1.DataBindings.Add(New Binding("Text", dataset1.Tables(0),
"LastName"))
///
I hope this helps

Cor
So how do you bind a textbox to a dataset. I can't get any of my data to
show up...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top