Databindings help

G

Graham Blandford

Hi all,

I haven't received any replies to a previous question I posted regarding
problems I was having with databound textboxes.. so I'll try a different
angle...

Can anyone point me in the direction of.. or give me some good examples of
databinding of a dataset/table to textboxes in a windows form using CODE -
being assigned at runtime.

I can establish a connection, dataadaptor, dataset all at runtime, and if I
can assign the datasource value of a datagrid, but I can't find any examples
of databound textboxes - these use databindings, and all the items I've
found on these assume you are assigning the datasource at design-time in the
IDE.

I have half the day trying to resolve this - moving from VB6 to .NET is
proving expensive and time-consuming.. any ideas would be greatly
appreciated...

Thanks,
Graham
 
K

Ken Tucker [MVP]

Hi,

Dim strConn As String
Dim strSQL As String
Dim da As OleDbDataAdapter

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"


conn = New OleDbConnection(strConn)
da = New OleDbDataAdapter("Select * From Categories", conn)
da.Fill(ds, "Categories")

TextBox2.DataBindings.Add("Text", ds.Tables("Categories"),
"CategoryName")
DataGrid1.DataSource = ds.Tables("Categories")

Ken
 
G

Graham Blandford

Hi Ken,
Thanks, that's what I basically have - doesn't work. So here's the thing - I
have now created the connection etc. thru the IDE and assigned the bindings
through the IDE. If I now make changes to the bound data.. it stil doesn't
perform the update. If I check the HasChanges it is false! ????

I'm at a loss... any ideas?.. I can;t see that I am doing anything wrong..

Thanks,
Graham
 
C

Cor Ligthert

Hi Graham,

Please keep the original thread, this is not a professional board however
individuals who try to help others. Some sleep do you know on times that you
are up.

Sometimes you get your answer in 5 minutes sometimes it can take 12 hours,
the most who helps in this newsgroup have a wide area, however no one knows
on every question an answer.

Your problem is however mostly this.
Set before the check for haschanges this

BindingContext(ds.Tables(0)).EndCurrentEdit()
or when you use more tables for that ds.tables(0) the right
dataset.tablename

I hope this helps?

Cor
 
G

Graham Blandford

Hi Cor,

Thanks again - I apologize for my 'impatience' - just a little frustrated -
having spent the last couple of years finally building a VB6 framework to
make my database development VERY easy - I'm thrown into the .NET arena with
little time to show some results..... always the way right? ;-)

Anyway, I do appreciate all the help I get here and have the highest
admiration for those people that go out of their way to assist people like
me.

Thanks,
Graham
 

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