How to Call a TableAdapter Insert command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randy

    #1

    How to Call a TableAdapter Insert command

    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(myD S.myTable)

    Thanks,
    Randy

  • Cor Ligthert [MVP]

    #2
    Re: How to Call a TableAdapter Insert command

    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.execute nonquery. For the dataadapter you could use databinding.

    Cor

    "Randy" <spam.eastland@ gmail.comschree f in bericht
    news:1178477859 .555301.215660@ q75g2000hsh.goo glegroups.com.. .
    >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(myD S.myTable)
    >
    Thanks,
    Randy
    >

    Comment

    • Randy

      #3
      Re: How to Call a TableAdapter Insert command

      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.Para meters.AddWithV alue" 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.Execu teNonQuery 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

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: How to Call a TableAdapter Insert command

        Randy,

        You can make it yourself much easier by databinding.
        You than have in pricipal only to load the tabel at the begin and update it
        at the end.
        (This is theoretical0

        Have a look at this sample on our website)





        To write you can for this kind of simple data use a commandbuilder

        Cor


        "Randy" <spam.eastland@ gmail.comschree f in bericht
        news:1178518465 .100716.4830@n5 9g2000hsh.googl egroups.com...
        >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.Para meters.AddWithV alue" 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.Execu teNonQuery 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
        >

        Comment

        Working...