bind data to txtbox from dataset?

R

Rich

Hello,

I am having a problem showing data in a form textbox which
is bound to a column in a table in a dataset. I have
successfully established a connection to an Access mdb,
successfully created the oledbadapter and successfully
created the dataset object. The table in the mdb is
tbl1. I named tbl1 as dtTbl1 in the dataset object ds1
and a field called fld1 as dcfld1. I can loop through the
dataset and see my data in the console window. So on the
form load event I say this:

Private sub Form_Load(...)
ds1.Clear()
oledbda1.Fill(ds1, "tbl1")
Me.BindingContext(ds1, "tbl1").Position = 0
End Sub

For the textbox, txt1 I go to the properties to
DataBinding, select ds1, tbl1, dcfld1 and press enter. So
when the form loads, shouldn't the data from the first row
first column appear in txt1? I am not seeing anything.
Any suggestions appreciated on what else I need to do to
make the data appear in txt1 based on databinding.

Thanks,
Rich
 
C

Cor

Hi Rich,

Did you see the message I have sended this morning (my time) in your
original thread?.

Cor
 
R

Rich

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
<<

Thank you. So if I type this code in my form load event
(assuming I have a textbox named "lastname") when I load
the form would data show up in the textbox automatically?
I believe the functionality is supposed to be the same as
if you bind a form/field in an Access mdb to a table.
When you load the form, the data shows up automatically in
Access. I noticed that in the code (generated by VS.net)
it already has something like

textbox1.DataBindings.Add(New Binding("Text",
dataset1.Tables(0),
"LastName")

So if I type your code in the form load event will the
form act the same as a bound form in Access?

Thank you for your information.
 
C

Cor

Hi Rich,

I thought let make a complete sample with a textbox, I had only a sample
with a combobox.
(I have deleted some things about the dataset again from my sample)

And before I forget it, that Lastname is not your textbox, but your database
Item, here as A.

I hope this helps a little bit?

Cor


\\\
Private cma As CurrencyManager
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
---------------
cma = CType(BindingContext(ds.Tables(0)), CurrencyManager)
textbox1.DataBindings.Add(New Binding("Text", ds.Tables(0), "A"))
End Sub
Private Sub mybuttonup(ByVal sender As Object, _
ByVal e As System.EventArgs)
If cma.Position < ds.Tables(0).Rows.Count - 1 Then
cma.Position += 1
End If
End Sub
Private Sub mybuttondown(ByVal sender As Object, _
ByVal e As System.EventArgs)
If cma.Position > 0 Then
cma.Position -= 1
End If
End Sub
////
 
R

Rich

Thank you very much for your help. I will try this out
and post back how it worked (tonight).

Rich
 
G

Guest

That did the trick! Thanks very much.


----- Rich wrote: -----

Thank you very much for your help. I will try this out
and post back how it worked (tonight).

Rich
 

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