Cannot bind a simple text box

  • Thread starter Lori Markle via .NET 247
  • Start date
L

Lori Markle via .NET 247

(Type your message here)
Hi,

I'm having a problem with binding a textbox to a dataset. Cananybody figure out what's going on here?

I simply want to update a record. Type in a permit number andsave it to the database. I get the "cannot bind to columnpermitnumber on datasource" error, or if I add the tablename.column name into the binding, a permit number that alreadyexists pops up.

Here is my code:
Dim dbConn As NewOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Projects\Tests\ParkingPErmits.mdb")
Dim da As New OleDbDataAdapter("select * from permits",dbConn)
Dim cb As New OleDbCommandBuilder(da)
Dim ds As New DataSet

da.UpdateCommand = cb.GetUpdateCommand
da.DeleteCommand = cb.GetDeleteCommand
da.InsertCommand = cb.GetInsertCommand
da.Fill(ds, "permits")

txtPermits.DataBindings.Clear()
txtPermits.DataBindings.Add("text", ds,"permits.permitnumber")

da.Update(ds, "permits")

Do I have something in incorrect order?

Thanks,
 
W

William Ryan eMVP

You are calling update after adding the bind, but nothing has changed.
For the record, if your dataset .HasChanges = false, you can call update all
year and nothing will happen. You'll probably want to set up a
bindingcontext and you'll need to change the values before an update will
happen.
http://www.knowdotnet.com/articles/datasetmerge.html

For future reference, add this line before your update in testing, this way
you'll Know if update is actually going to get called (and just b/c it does,
doesn't mean it will work, but if you get a big ugly assertion box, you KNOW
nothing will happen with the Update)

Debug.Assert(DataSetName.HasChanges, "No Changes Detected")
(Type your message here)
Hi,

I'm having a problem with binding a textbox to a dataset. Can anybody figure
out what's going on here?

I simply want to update a record. Type in a permit number and save it to the
database. I get the "cannot bind to column permitnumber on datasource"
error, or if I add the table name.column name into the binding, a permit
number that already exists pops up.

Here is my code:
Dim dbConn As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Projects\Tests\ParkingPErmits.mdb")
Dim da As New OleDbDataAdapter("select * from permits", dbConn)
Dim cb As New OleDbCommandBuilder(da)
Dim ds As New DataSet

da.UpdateCommand = cb.GetUpdateCommand
da.DeleteCommand = cb.GetDeleteCommand
da.InsertCommand = cb.GetInsertCommand
da.Fill(ds, "permits")

txtPermits.DataBindings.Clear()
txtPermits.DataBindings.Add("text", ds, "permits.permitnumber")

da.Update(ds, "permits")

Do I have something in incorrect order?

Thanks,
 
S

sparkle

OK! Now I'm getting somewhere!

I'll try both answers out and see what happens.

Thanks, William...
 

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