How to Call a TableAdapter Insert command

R

Randy

I think that this is a really simple question. I have a table adapter
set up with the various sql queries. I'd like to allow the user to
make changes to a given row on a form. Each of the changes is made
using textboxes (not a data grid). Once done, they click a Save
button, which should call the insert query on the tableadapter. I
can't seem to figure out how to call this. I could do it using a data
adapter, but there are many fields, so writing the query in code would
be very long and it's already there in the table adapter. Plus, if I
ever change the table schema, I can just change the insert command in
the TA and not have to update it my code.

Can anybody tell me what the code is to call this insert command?
e.g. myTA.Insert(myDS.myTable)

Thanks,
Randy
 
C

Cor Ligthert [MVP]

Randy,

I think that you first have to ask yourself why you use a table as you
access all boxes seperatly. For the later you can use the
command.executenonquery. For the dataadapter you could use databinding.

Cor
 
R

Randy

I have 37 text/combo boxes on my form, all relating to fields on a
single table. I'm using text and comboboxes rather than a data grid
simply so that I can organize the form in a user-friendly manner.
Right now, I've got 37 lines that start with
"cmdUpdate.Parameters.AddWithValue" so that I can pass the values of
each of these boxes into my parameterized sql statement. Since I am
just using a single table, I was hoping that I can take advantage of
the table adapter on this table to avoid all of those parameter lines
before I get to the cmdUpdate.ExecuteNonQuery call. It's just a lot
of lines to create and execute for something that is so conceptually
simple. Does that make sense?

Maybe databinding is a better answer. I'm still not very proficient
with this. I'll have to do some studying on that topic. That's a
good suggestion.

Thanks, Cor. I appreciate you thinking about this for me.

Randy
 

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