By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,351 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,351 IT Pros & Developers. It's quick & easy.

efficiently update datasouce from form with many textboxes

P: n/a
I have a form with 36 text boxes on it. I have everything working for
the user to make changes to existing records or to add new ones. When
I come to the point of passing this data on to the data source, I'm
looking for an efficient way to do this. The only way that I know of
is a line-by-line procedure that passes each textbox to the
appropriate field in the data table one-by-one. Example:

Dim drNew As DataRow

drNew = dsMyDataSet.myTable.NewRow()

drNew.Item("Column1") = TextBox1.text
drNew.Item("Column2") = TextBox2.text
drNew.Item("Column3") = TextBox3.text
(etc, etc, through 36 text boxes)

dsMyDataSet.MyTable.Rows.Add(drNew)
taMyTableAdapter.Update(dsMyDataSet.MyTable)
dsMyDataSet.AcceptChanges()

I'd like to find a loop that would work something like this (more or
less):

Dim c As Control
Dim x as integer

For Each c In Me.Controls
If TypeOf c Is TextBox Then
Dim tb As TextBox = DirectCast(c, TextBox)
x = +1
drNew.Item(x)=c.text
End If
Next

Anybody have any ideas?

Thanks,
Randy

Apr 22 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Data bind the textboxes to the data source, and they will be passed
automatically.

Robin S.
---------------------------
"Randy" <sp***********@gmail.comwrote in message
news:11*********************@b75g2000hsg.googlegro ups.com...
>I have a form with 36 text boxes on it. I have everything working for
the user to make changes to existing records or to add new ones. When
I come to the point of passing this data on to the data source, I'm
looking for an efficient way to do this. The only way that I know of
is a line-by-line procedure that passes each textbox to the
appropriate field in the data table one-by-one. Example:

Dim drNew As DataRow

drNew = dsMyDataSet.myTable.NewRow()

drNew.Item("Column1") = TextBox1.text
drNew.Item("Column2") = TextBox2.text
drNew.Item("Column3") = TextBox3.text
(etc, etc, through 36 text boxes)

dsMyDataSet.MyTable.Rows.Add(drNew)
taMyTableAdapter.Update(dsMyDataSet.MyTable)
dsMyDataSet.AcceptChanges()

I'd like to find a loop that would work something like this (more or
less):

Dim c As Control
Dim x as integer

For Each c In Me.Controls
If TypeOf c Is TextBox Then
Dim tb As TextBox = DirectCast(c, TextBox)
x = +1
drNew.Item(x)=c.text
End If
Next

Anybody have any ideas?

Thanks,
Randy

Apr 22 '07 #2

P: n/a
Randy,

It is about 2 textboxes, but that should not make the difference.

http://www.vb-tips.com/dbpages.aspx?...8-4e3f3fedb997

I hope this helps,

Cor

"Randy" <sp***********@gmail.comschreef in bericht
news:11*********************@b75g2000hsg.googlegro ups.com...
>I have a form with 36 text boxes on it. I have everything working for
the user to make changes to existing records or to add new ones. When
I come to the point of passing this data on to the data source, I'm
looking for an efficient way to do this. The only way that I know of
is a line-by-line procedure that passes each textbox to the
appropriate field in the data table one-by-one. Example:

Dim drNew As DataRow

drNew = dsMyDataSet.myTable.NewRow()

drNew.Item("Column1") = TextBox1.text
drNew.Item("Column2") = TextBox2.text
drNew.Item("Column3") = TextBox3.text
(etc, etc, through 36 text boxes)

dsMyDataSet.MyTable.Rows.Add(drNew)
taMyTableAdapter.Update(dsMyDataSet.MyTable)
dsMyDataSet.AcceptChanges()

I'd like to find a loop that would work something like this (more or
less):

Dim c As Control
Dim x as integer

For Each c In Me.Controls
If TypeOf c Is TextBox Then
Dim tb As TextBox = DirectCast(c, TextBox)
x = +1
drNew.Item(x)=c.text
End If
Next

Anybody have any ideas?

Thanks,
Randy

Apr 22 '07 #3

P: n/a
On Apr 22, 1:56 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
Data bind the textboxes to the data source, and they will be passed
automatically.
I tried this, but it isn't working as intended. For the textbox that
is supposed to update the primary field, I have its text bound to
IngredientsBindingSource - Ingredients, which follows from the
dataset. Is this the correct place to bind for this purpose? Also,
how do I trigger the data to be passed to the datasource. As there
are many textboxes on this form, I want the user to fill them all in
and then click a Save button, which will trigger the data to be
persisted to the datasource.

Anything else that I need to know? I've been through a couple of
books over the last few weeks and am slowly understanding some of
these ideas. I didn't realize that a bindingsource could be used to
push data all the way back to the source. I thought that it just was
used for the dataset.

Apr 22 '07 #4

P: n/a
You databind each control to a specific field in your table. You can do
this in a multitude of ways. I use business objects, so I do object
binding. If you have a strongly typed dataset, you can show the data source
and just drag from the data source onto your control. Or you can manually
bind behind the scenes.

It sounds like you are showing a data source and dragged it onto the form,
or onto a control. Is that right?

When the user tabs out of a databound control, it pushes the number down
into the dataset in memory. Usually, you do a call to myForm.Validate()
when he hits save, so if he hasn't tabbed out of the last field he changed,
it picks up the change. After the call to Validate, you would call
myAdapter.Save() and it would iterate through the records and save them as
discussed in the other thread.

The binding source is kind of the glue, or lubricant. You don't *have* to
use a binding source. You can bind directly to the data source. However,
using a binding source speeds up the display to the screen, and any changes
to the data source are immediately displayed by the binding source. It also
gives you a bunch of extra fun stuff to play with, like sorting and
filtering.

For some really excellent information on data binding, check out Brian
Noyes' Data Binding book. It's in C#, but the downloadable code is also
available in VB. It was invaluable to me.

Does that help?

Robin S.
----------------------------------
"Randy" <sp***********@gmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
On Apr 22, 1:56 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
>Data bind the textboxes to the data source, and they will be passed
automatically.

I tried this, but it isn't working as intended. For the textbox that
is supposed to update the primary field, I have its text bound to
IngredientsBindingSource - Ingredients, which follows from the
dataset. Is this the correct place to bind for this purpose? Also,
how do I trigger the data to be passed to the datasource. As there
are many textboxes on this form, I want the user to fill them all in
and then click a Save button, which will trigger the data to be
persisted to the datasource.

Anything else that I need to know? I've been through a couple of
books over the last few weeks and am slowly understanding some of
these ideas. I didn't realize that a bindingsource could be used to
push data all the way back to the source. I thought that it just was
used for the dataset.

Apr 24 '07 #5

P: n/a
Robin,

Don't you have to do otherthins there in SF, it seems it looks a lot like
Holland (the real Holland). But we don't look how we can win, half a
picosecond.

Cor

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:w9******************************@comcast.com. ..
You databind each control to a specific field in your table. You can do
this in a multitude of ways. I use business objects, so I do object
binding. If you have a strongly typed dataset, you can show the data
source and just drag from the data source onto your control. Or you can
manually bind behind the scenes.

It sounds like you are showing a data source and dragged it onto the form,
or onto a control. Is that right?

When the user tabs out of a databound control, it pushes the number down
into the dataset in memory. Usually, you do a call to myForm.Validate()
when he hits save, so if he hasn't tabbed out of the last field he
changed, it picks up the change. After the call to Validate, you would
call myAdapter.Save() and it would iterate through the records and save
them as discussed in the other thread.

The binding source is kind of the glue, or lubricant. You don't *have* to
use a binding source. You can bind directly to the data source. However,
using a binding source speeds up the display to the screen, and any
changes to the data source are immediately displayed by the binding
source. It also gives you a bunch of extra fun stuff to play with, like
sorting and filtering.

For some really excellent information on data binding, check out Brian
Noyes' Data Binding book. It's in C#, but the downloadable code is also
available in VB. It was invaluable to me.

Does that help?

Robin S.
----------------------------------
"Randy" <sp***********@gmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
>On Apr 22, 1:56 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
>>Data bind the textboxes to the data source, and they will be passed
automatically.

I tried this, but it isn't working as intended. For the textbox that
is supposed to update the primary field, I have its text bound to
IngredientsBindingSource - Ingredients, which follows from the
dataset. Is this the correct place to bind for this purpose? Also,
how do I trigger the data to be passed to the datasource. As there
are many textboxes on this form, I want the user to fill them all in
and then click a Save button, which will trigger the data to be
persisted to the datasource.

Anything else that I need to know? I've been through a couple of
books over the last few weeks and am slowly understanding some of
these ideas. I didn't realize that a bindingsource could be used to
push data all the way back to the source. I thought that it just was
used for the dataset.


Apr 25 '07 #6

P: n/a
I'm not really sure what you mean, Cor. I wasn't telling the guy how to get
better performance, I was trying to figure out what he was talking about
and how to help him.

I haven't had the privilege of visiting Holland, although the pictures I
see of it are beautiful. I think biking along those canals would be really
cool. And isn't it warmer in Holland than it is here? It's like 60-70 in SF
most of the time.

Robin S.
---------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eK**************@TK2MSFTNGP05.phx.gbl...
Robin,

Don't you have to do otherthins there in SF, it seems it looks a lot like
Holland (the real Holland). But we don't look how we can win, half a
picosecond.

Cor

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:w9******************************@comcast.com. ..
>You databind each control to a specific field in your table. You can do
this in a multitude of ways. I use business objects, so I do object
binding. If you have a strongly typed dataset, you can show the data
source and just drag from the data source onto your control. Or you can
manually bind behind the scenes.

It sounds like you are showing a data source and dragged it onto the
form, or onto a control. Is that right?

When the user tabs out of a databound control, it pushes the number down
into the dataset in memory. Usually, you do a call to myForm.Validate()
when he hits save, so if he hasn't tabbed out of the last field he
changed, it picks up the change. After the call to Validate, you would
call myAdapter.Save() and it would iterate through the records and save
them as discussed in the other thread.

The binding source is kind of the glue, or lubricant. You don't *have*
to use a binding source. You can bind directly to the data source.
However, using a binding source speeds up the display to the screen, and
any changes to the data source are immediately displayed by the binding
source. It also gives you a bunch of extra fun stuff to play with, like
sorting and filtering.

For some really excellent information on data binding, check out Brian
Noyes' Data Binding book. It's in C#, but the downloadable code is also
available in VB. It was invaluable to me.

Does that help?

Robin S.
----------------------------------
"Randy" <sp***********@gmail.comwrote in message
news:11**********************@d57g2000hsg.googleg roups.com...
>>On Apr 22, 1:56 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
Data bind the textboxes to the data source, and they will be passed
automatically.

I tried this, but it isn't working as intended. For the textbox that
is supposed to update the primary field, I have its text bound to
IngredientsBindingSource - Ingredients, which follows from the
dataset. Is this the correct place to bind for this purpose? Also,
how do I trigger the data to be passed to the datasource. As there
are many textboxes on this form, I want the user to fill them all in
and then click a Save button, which will trigger the data to be
persisted to the datasource.

Anything else that I need to know? I've been through a couple of
books over the last few weeks and am slowly understanding some of
these ideas. I didn't realize that a bindingsource could be used to
push data all the way back to the source. I thought that it just was
used for the dataset.



Apr 27 '07 #7

P: n/a
RobinS,

I know that you were telling on better performance, but I was telling you
that I thought that they were used in SF to spent there time an better
things like here in Amsterdam than how to win a picosecond. I haven't been
there too, but about reading from it, it are too people who are very
realistic. Therefore I wrote this, spending your time on pico seconds as we
are doing now is in my opinion ridiculous, I was of course not writting to
you but indirect to the OP. But I thought people from SF can easier
understand why I wrote this.

I assume that the climat in SF is like Amsterdam, when I see pictures people
are dressed the same.

Cor

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:Q6******************************@comcast.com. ..
I'm not really sure what you mean, Cor. I wasn't telling the guy how to
get better performance, I was trying to figure out what he was talking
about and how to help him.

I haven't had the privilege of visiting Holland, although the pictures I
see of it are beautiful. I think biking along those canals would be really
cool. And isn't it warmer in Holland than it is here? It's like 60-70 in
SF most of the time.

Robin S.
---------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eK**************@TK2MSFTNGP05.phx.gbl...
>Robin,

Don't you have to do otherthins there in SF, it seems it looks a lot like
Holland (the real Holland). But we don't look how we can win, half a
picosecond.

Cor

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:w9******************************@comcast.com ...
>>You databind each control to a specific field in your table. You can do
this in a multitude of ways. I use business objects, so I do object
binding. If you have a strongly typed dataset, you can show the data
source and just drag from the data source onto your control. Or you can
manually bind behind the scenes.

It sounds like you are showing a data source and dragged it onto the
form, or onto a control. Is that right?

When the user tabs out of a databound control, it pushes the number down
into the dataset in memory. Usually, you do a call to myForm.Validate()
when he hits save, so if he hasn't tabbed out of the last field he
changed, it picks up the change. After the call to Validate, you would
call myAdapter.Save() and it would iterate through the records and save
them as discussed in the other thread.

The binding source is kind of the glue, or lubricant. You don't *have*
to use a binding source. You can bind directly to the data source.
However, using a binding source speeds up the display to the screen, and
any changes to the data source are immediately displayed by the binding
source. It also gives you a bunch of extra fun stuff to play with, like
sorting and filtering.

For some really excellent information on data binding, check out Brian
Noyes' Data Binding book. It's in C#, but the downloadable code is also
available in VB. It was invaluable to me.

Does that help?

Robin S.
----------------------------------
"Randy" <sp***********@gmail.comwrote in message
news:11**********************@d57g2000hsg.google groups.com...
On Apr 22, 1:56 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
Data bind the textboxes to the data source, and they will be passed
automatically.

I tried this, but it isn't working as intended. For the textbox that
is supposed to update the primary field, I have its text bound to
IngredientsBindingSource - Ingredients, which follows from the
dataset. Is this the correct place to bind for this purpose? Also,
how do I trigger the data to be passed to the datasource. As there
are many textboxes on this form, I want the user to fill them all in
and then click a Save button, which will trigger the data to be
persisted to the datasource.

Anything else that I need to know? I've been through a couple of
books over the last few weeks and am slowly understanding some of
these ideas. I didn't realize that a bindingsource could be used to
push data all the way back to the source. I thought that it just was
used for the dataset.



Apr 29 '07 #8

P: n/a
Hi, Cor,

I actually wasn't talking about getting better performance at all, I was
talking about how to use data binding. I agree with you, trying to make
something an itsy bitsy bit faster usually takes more time than it's worth.

It was 50 deg F here 3 days ago, 97 deg F two days ago, 70 deg F yesterday,
and 65 deg F today. Weird. We can have a 40 deg F swing during the day. I
live about 30 mi. east of SF, in a valley, and our temperatures are a lot
more extreme than the city itself. The company I work for is in SF, but I
am lucky enough to be able to telecommute, and only go in to the city a
couple of days a month.

Some day I will come to Holland; maybe we can get together for a drink. :-)

Robin S.
------------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uW**************@TK2MSFTNGP04.phx.gbl...
RobinS,

I know that you were telling on better performance, but I was telling you
that I thought that they were used in SF to spent there time an better
things like here in Amsterdam than how to win a picosecond. I haven't
been there too, but about reading from it, it are too people who are very
realistic. Therefore I wrote this, spending your time on pico seconds as
we are doing now is in my opinion ridiculous, I was of course not
writting to you but indirect to the OP. But I thought people from SF can
easier understand why I wrote this.

I assume that the climat in SF is like Amsterdam, when I see pictures
people are dressed the same.

Cor

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:Q6******************************@comcast.com. ..
>I'm not really sure what you mean, Cor. I wasn't telling the guy how to
get better performance, I was trying to figure out what he was talking
about and how to help him.

I haven't had the privilege of visiting Holland, although the pictures I
see of it are beautiful. I think biking along those canals would be
really cool. And isn't it warmer in Holland than it is here? It's like
60-70 in SF most of the time.

Robin S.
---------------------
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eK**************@TK2MSFTNGP05.phx.gbl...
>>Robin,

Don't you have to do otherthins there in SF, it seems it looks a lot
like Holland (the real Holland). But we don't look how we can win, half
a picosecond.

Cor

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:w9******************************@comcast.co m...
You databind each control to a specific field in your table. You can
do this in a multitude of ways. I use business objects, so I do object
binding. If you have a strongly typed dataset, you can show the data
source and just drag from the data source onto your control. Or you
can manually bind behind the scenes.

It sounds like you are showing a data source and dragged it onto the
form, or onto a control. Is that right?

When the user tabs out of a databound control, it pushes the number
down into the dataset in memory. Usually, you do a call to
myForm.Validate() when he hits save, so if he hasn't tabbed out of the
last field he changed, it picks up the change. After the call to
Validate, you would call myAdapter.Save() and it would iterate through
the records and save them as discussed in the other thread.

The binding source is kind of the glue, or lubricant. You don't *have*
to use a binding source. You can bind directly to the data source.
However, using a binding source speeds up the display to the screen,
and any changes to the data source are immediately displayed by the
binding source. It also gives you a bunch of extra fun stuff to play
with, like sorting and filtering.

For some really excellent information on data binding, check out Brian
Noyes' Data Binding book. It's in C#, but the downloadable code is
also available in VB. It was invaluable to me.

Does that help?

Robin S.
----------------------------------
"Randy" <sp***********@gmail.comwrote in message
news:11**********************@d57g2000hsg.googl egroups.com...
On Apr 22, 1:56 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
>Data bind the textboxes to the data source, and they will be passed
>automatically.
>
I tried this, but it isn't working as intended. For the textbox that
is supposed to update the primary field, I have its text bound to
IngredientsBindingSource - Ingredients, which follows from the
dataset. Is this the correct place to bind for this purpose? Also,
how do I trigger the data to be passed to the datasource. As there
are many textboxes on this form, I want the user to fill them all in
and then click a Save button, which will trigger the data to be
persisted to the datasource.
>
Anything else that I need to know? I've been through a couple of
books over the last few weeks and am slowly understanding some of
these ideas. I didn't realize that a bindingsource could be used to
push data all the way back to the source. I thought that it just was
used for the dataset.
>




May 1 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.