howto use params with insertCmd for DataAdapter?

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

    howto use params with insertCmd for DataAdapter?

    Greetings,

    Just starting out with .net. I have a vb.net app where I
    connect to an Access mdb. I use a connection component
    from the tool box (conn1), a data adapter component from
    the toolbox (da1) and create a typed dataset (ds1) and
    populate a grid on a form (grd1). This all works fine and
    I can see data from the Access mdb in the grid. But now I
    want to add a record to the mdb.

    In the data adapter da1 I see in the property sheet a
    select command (selcmd1), insert command (insCmd1) and
    delete command. For insCmd1 I set the connection to
    conn1. Then I want to set the parameters. I have 3
    fields in the Access table, fld1 (text), fld2 (number),
    fld3 (date). In the Paramters dialog box of da1 for
    insCmd1 I see a "Source Column" field, a "Value" field and
    a "Parameter Name" field. On my vb form I have 3
    textboxes, txt1, txt2, txt3. I want parm1 to have the
    value in txt1, parm2 has value for txt2, parm3 for txt3.
    Question: what do I put in the "Source Column field" for
    parm1? How do I tell it to retrieve the value of
    txt1.text? and so on.

    Then I have a button (btn1) on the form which I click to
    carry out the insert operation. I am not clear on the
    syntax for carrying this out. Do I still have to say
    insCmd1.Paramte rs.Add(txt1)
    ....
    da1.SelectCmd = insCmd1
    da1.InsertComma nd = insCmd1.somethi ng

    Well, this is what I tried without any success. Any
    advice how to do this would be greatly appreciated.

    Thanks,
    Rich
  • Cor

    #2
    Re: howto use params with insertCmd for DataAdapter?

    Hi Rich,

    In the adonet group are some guys who hate this.

    But to start just do this (forget the insert, the update and the
    deletecommand a while)

    DirectCast(Bind ingContext(ds.t ables(0)), CurrencyManager ).EndCurrentEdi t()
    Dim da As New OleDbDataAdapte r("OriginalSele ctString",conne ction)
    Dim cb As New OleDbCommandBui lder(da)
    If ds.HasChanges Then
    da.Update(ds)
    End If

    With difficult select strings the commandbuilder can give errors.

    You can probably forgot that da and replace it in the commandbuilder with
    da1

    I hope this helps?

    Cor[color=blue]
    >
    > Just starting out with .net. I have a vb.net app where I
    > connect to an Access mdb. I use a connection component
    > from the tool box (conn1), a data adapter component from
    > the toolbox (da1) and create a typed dataset (ds1) and
    > populate a grid on a form (grd1). This all works fine and
    > I can see data from the Access mdb in the grid. But now I
    > want to add a record to the mdb.
    >
    > In the data adapter da1 I see in the property sheet a
    > select command (selcmd1), insert command (insCmd1) and
    > delete command. For insCmd1 I set the connection to
    > conn1. Then I want to set the parameters. I have 3
    > fields in the Access table, fld1 (text), fld2 (number),
    > fld3 (date). In the Paramters dialog box of da1 for
    > insCmd1 I see a "Source Column" field, a "Value" field and
    > a "Parameter Name" field. On my vb form I have 3
    > textboxes, txt1, txt2, txt3. I want parm1 to have the
    > value in txt1, parm2 has value for txt2, parm3 for txt3.
    > Question: what do I put in the "Source Column field" for
    > parm1? How do I tell it to retrieve the value of
    > txt1.text? and so on.
    >
    > Then I have a button (btn1) on the form which I click to
    > carry out the insert operation. I am not clear on the
    > syntax for carrying this out. Do I still have to say
    > insCmd1.Paramte rs.Add(txt1)
    > ...
    > da1.SelectCmd = insCmd1
    > da1.InsertComma nd = insCmd1.somethi ng
    >
    > Well, this is what I tried without any success. Any
    > advice how to do this would be greatly appreciated.
    >[/color]


    Comment

    • Rich

      #3
      Re: howto use params with insertCmd for DataAdapter?

      Hi Cor,

      Thanks for your reply. Finally got vs.net2003 loaded on
      my computer.

      Question: My data is displayed in the grid control. The
      textboxes on the form are unbound textboxes. Should I
      bind the textboxes to the dataset? If not, how do I
      reference the textboxes, as they are the parameters I want
      to insert in the new record?

      Thanks again,
      Rich

      [color=blue]
      >-----Original Message-----
      >Hi Rich,
      >
      >In the adonet group are some guys who hate this.
      >
      >But to start just do this (forget the insert, the update[/color]
      and the[color=blue]
      >deletecomman d a while)
      >
      >DirectCast(Bin dingContext(ds. tables(0)),[/color]
      CurrencyManager ).EndCurrentEdi t()[color=blue]
      >Dim da As New OleDbDataAdapte r[/color]
      ("OriginalSelec tString",connec tion)[color=blue]
      >Dim cb As New OleDbCommandBui lder(da)
      >If ds.HasChanges Then
      > da.Update(ds)
      >End If
      >
      >With difficult select strings the commandbuilder can give[/color]
      errors.[color=blue]
      >
      >You can probably forgot that da and replace it in the[/color]
      commandbuilder with[color=blue]
      >da1
      >
      >I hope this helps?
      >
      >Cor[color=green]
      >>
      >> Just starting out with .net. I have a vb.net app where[/color][/color]
      I[color=blue][color=green]
      >> connect to an Access mdb. I use a connection component
      >> from the tool box (conn1), a data adapter component from
      >> the toolbox (da1) and create a typed dataset (ds1) and
      >> populate a grid on a form (grd1). This all works fine[/color][/color]
      and[color=blue][color=green]
      >> I can see data from the Access mdb in the grid. But[/color][/color]
      now I[color=blue][color=green]
      >> want to add a record to the mdb.
      >>
      >> In the data adapter da1 I see in the property sheet a
      >> select command (selcmd1), insert command (insCmd1) and
      >> delete command. For insCmd1 I set the connection to
      >> conn1. Then I want to set the parameters. I have 3
      >> fields in the Access table, fld1 (text), fld2 (number),
      >> fld3 (date). In the Paramters dialog box of da1 for
      >> insCmd1 I see a "Source Column" field, a "Value" field[/color][/color]
      and[color=blue][color=green]
      >> a "Parameter Name" field. On my vb form I have 3
      >> textboxes, txt1, txt2, txt3. I want parm1 to have the
      >> value in txt1, parm2 has value for txt2, parm3 for txt3.
      >> Question: what do I put in the "Source Column field"[/color][/color]
      for[color=blue][color=green]
      >> parm1? How do I tell it to retrieve the value of
      >> txt1.text? and so on.
      >>
      >> Then I have a button (btn1) on the form which I click to
      >> carry out the insert operation. I am not clear on the
      >> syntax for carrying this out. Do I still have to say
      >> insCmd1.Paramte rs.Add(txt1)
      >> ...
      >> da1.SelectCmd = insCmd1
      >> da1.InsertComma nd = insCmd1.somethi ng
      >>
      >> Well, this is what I tried without any success. Any
      >> advice how to do this would be greatly appreciated.
      >>[/color]
      >
      >
      >.
      >[/color]

      Comment

      • Cor

        #4
        Re: howto use params with insertCmd for DataAdapter?

        Hi Rich,

        Normaly you do not have to do nothing to insert a new row, just start typing
        at the bottom.

        If you want it sorted have a look at the dataview, that you can put between
        your dataset and the datagrid.

        Something as dirty typed of course.
        \\\
        dim dv as new dataview(ds.tab les(0))
        dv.sort = "mycolumnam e"
        datagrid.dataso urce = dv
        ///
        Cor
        [color=blue]
        >
        > Thanks for your reply. Finally got vs.net2003 loaded on
        > my computer.
        >
        > Question: My data is displayed in the grid control. The
        > textboxes on the form are unbound textboxes. Should I
        > bind the textboxes to the dataset? If not, how do I
        > reference the textboxes, as they are the parameters I want
        > to insert in the new record?
        >
        > Thanks again,
        > Rich
        >
        >[color=green]
        > >-----Original Message-----
        > >Hi Rich,
        > >
        > >In the adonet group are some guys who hate this.
        > >
        > >But to start just do this (forget the insert, the update[/color]
        > and the[color=green]
        > >deletecomman d a while)
        > >
        > >DirectCast(Bin dingContext(ds. tables(0)),[/color]
        > CurrencyManager ).EndCurrentEdi t()[color=green]
        > >Dim da As New OleDbDataAdapte r[/color]
        > ("OriginalSelec tString",connec tion)[color=green]
        > >Dim cb As New OleDbCommandBui lder(da)
        > >If ds.HasChanges Then
        > > da.Update(ds)
        > >End If
        > >
        > >With difficult select strings the commandbuilder can give[/color]
        > errors.[color=green]
        > >
        > >You can probably forgot that da and replace it in the[/color]
        > commandbuilder with[color=green]
        > >da1
        > >
        > >I hope this helps?
        > >
        > >Cor[color=darkred]
        > >>
        > >> Just starting out with .net. I have a vb.net app where[/color][/color]
        > I[color=green][color=darkred]
        > >> connect to an Access mdb. I use a connection component
        > >> from the tool box (conn1), a data adapter component from
        > >> the toolbox (da1) and create a typed dataset (ds1) and
        > >> populate a grid on a form (grd1). This all works fine[/color][/color]
        > and[color=green][color=darkred]
        > >> I can see data from the Access mdb in the grid. But[/color][/color]
        > now I[color=green][color=darkred]
        > >> want to add a record to the mdb.
        > >>
        > >> In the data adapter da1 I see in the property sheet a
        > >> select command (selcmd1), insert command (insCmd1) and
        > >> delete command. For insCmd1 I set the connection to
        > >> conn1. Then I want to set the parameters. I have 3
        > >> fields in the Access table, fld1 (text), fld2 (number),
        > >> fld3 (date). In the Paramters dialog box of da1 for
        > >> insCmd1 I see a "Source Column" field, a "Value" field[/color][/color]
        > and[color=green][color=darkred]
        > >> a "Parameter Name" field. On my vb form I have 3
        > >> textboxes, txt1, txt2, txt3. I want parm1 to have the
        > >> value in txt1, parm2 has value for txt2, parm3 for txt3.
        > >> Question: what do I put in the "Source Column field"[/color][/color]
        > for[color=green][color=darkred]
        > >> parm1? How do I tell it to retrieve the value of
        > >> txt1.text? and so on.
        > >>
        > >> Then I have a button (btn1) on the form which I click to
        > >> carry out the insert operation. I am not clear on the
        > >> syntax for carrying this out. Do I still have to say
        > >> insCmd1.Paramte rs.Add(txt1)
        > >> ...
        > >> da1.SelectCmd = insCmd1
        > >> da1.InsertComma nd = insCmd1.somethi ng
        > >>
        > >> Well, this is what I tried without any success. Any
        > >> advice how to do this would be greatly appreciated.
        > >>[/color]
        > >
        > >
        > >.
        > >[/color][/color]


        Comment

        • Rich

          #5
          Re: howto use params with insertCmd for DataAdapter?

          OK. I try that. But I have one other problem. When I
          type

          Dim cb As New OleDBCommandBui lder(...)

          it says that OleDBCommandbui lder is not defined. Do I
          need an Imports statement? I am checking help files right
          now.

          [color=blue]
          >-----Original Message-----
          >Hi Rich,
          >
          >Normaly you do not have to do nothing to insert a new[/color]
          row, just start typing[color=blue]
          >at the bottom.
          >
          >If you want it sorted have a look at the dataview, that[/color]
          you can put between[color=blue]
          >your dataset and the datagrid.
          >
          >Something as dirty typed of course.
          >\\\
          >dim dv as new dataview(ds.tab les(0))
          >dv.sort = "mycolumnam e"
          >datagrid.datas ource = dv
          >///
          >Cor
          >[color=green]
          >>
          >> Thanks for your reply. Finally got vs.net2003 loaded on
          >> my computer.
          >>
          >> Question: My data is displayed in the grid control.[/color][/color]
          The[color=blue][color=green]
          >> textboxes on the form are unbound textboxes. Should I
          >> bind the textboxes to the dataset? If not, how do I
          >> reference the textboxes, as they are the parameters I[/color][/color]
          want[color=blue][color=green]
          >> to insert in the new record?
          >>
          >> Thanks again,
          >> Rich
          >>
          >>[color=darkred]
          >> >-----Original Message-----
          >> >Hi Rich,
          >> >
          >> >In the adonet group are some guys who hate this.
          >> >
          >> >But to start just do this (forget the insert, the[/color][/color][/color]
          update[color=blue][color=green]
          >> and the[color=darkred]
          >> >deletecomman d a while)
          >> >
          >> >DirectCast(Bin dingContext(ds. tables(0)),[/color]
          >> CurrencyManager ).EndCurrentEdi t()[color=darkred]
          >> >Dim da As New OleDbDataAdapte r[/color]
          >> ("OriginalSelec tString",connec tion)[color=darkred]
          >> >Dim cb As New OleDbCommandBui lder(da)
          >> >If ds.HasChanges Then
          >> > da.Update(ds)
          >> >End If
          >> >
          >> >With difficult select strings the commandbuilder can[/color][/color][/color]
          give[color=blue][color=green]
          >> errors.[color=darkred]
          >> >
          >> >You can probably forgot that da and replace it in the[/color]
          >> commandbuilder with[color=darkred]
          >> >da1
          >> >
          >> >I hope this helps?
          >> >
          >> >Cor
          >> >>
          >> >> Just starting out with .net. I have a vb.net app[/color][/color][/color]
          where[color=blue][color=green]
          >> I[color=darkred]
          >> >> connect to an Access mdb. I use a connection[/color][/color][/color]
          component[color=blue][color=green][color=darkred]
          >> >> from the tool box (conn1), a data adapter component[/color][/color][/color]
          from[color=blue][color=green][color=darkred]
          >> >> the toolbox (da1) and create a typed dataset (ds1)[/color][/color][/color]
          and[color=blue][color=green][color=darkred]
          >> >> populate a grid on a form (grd1). This all works[/color][/color][/color]
          fine[color=blue][color=green]
          >> and[color=darkred]
          >> >> I can see data from the Access mdb in the grid. But[/color]
          >> now I[color=darkred]
          >> >> want to add a record to the mdb.
          >> >>
          >> >> In the data adapter da1 I see in the property sheet a
          >> >> select command (selcmd1), insert command (insCmd1)[/color][/color][/color]
          and[color=blue][color=green][color=darkred]
          >> >> delete command. For insCmd1 I set the connection to
          >> >> conn1. Then I want to set the parameters. I have 3
          >> >> fields in the Access table, fld1 (text), fld2[/color][/color][/color]
          (number),[color=blue][color=green][color=darkred]
          >> >> fld3 (date). In the Paramters dialog box of da1 for
          >> >> insCmd1 I see a "Source Column" field, a "Value"[/color][/color][/color]
          field[color=blue][color=green]
          >> and[color=darkred]
          >> >> a "Parameter Name" field. On my vb form I have 3
          >> >> textboxes, txt1, txt2, txt3. I want parm1 to have[/color][/color][/color]
          the[color=blue][color=green][color=darkred]
          >> >> value in txt1, parm2 has value for txt2, parm3 for[/color][/color][/color]
          txt3.[color=blue][color=green][color=darkred]
          >> >> Question: what do I put in the "Source Column field"[/color]
          >> for[color=darkred]
          >> >> parm1? How do I tell it to retrieve the value of
          >> >> txt1.text? and so on.
          >> >>
          >> >> Then I have a button (btn1) on the form which I[/color][/color][/color]
          click to[color=blue][color=green][color=darkred]
          >> >> carry out the insert operation. I am not clear on[/color][/color][/color]
          the[color=blue][color=green][color=darkred]
          >> >> syntax for carrying this out. Do I still have to say
          >> >> insCmd1.Paramte rs.Add(txt1)
          >> >> ...
          >> >> da1.SelectCmd = insCmd1
          >> >> da1.InsertComma nd = insCmd1.somethi ng
          >> >>
          >> >> Well, this is what I tried without any success. Any
          >> >> advice how to do this would be greatly appreciated.
          >> >>
          >> >
          >> >
          >> >.
          >> >[/color][/color]
          >
          >
          >.
          >[/color]

          Comment

          • Cor

            #6
            Re: howto use params with insertCmd for DataAdapter?

            Hi Rich,

            Yes Imports System.OleDb

            Yes or just place OleDb. before it.

            Cor[color=blue]
            > OK. I try that. But I have one other problem. When I
            > type
            >
            > Dim cb As New OleDBCommandBui lder(...)
            >
            > it says that OleDBCommandbui lder is not defined. Do I
            > need an Imports statement? I am checking help files right
            > now.[/color]


            Comment

            • Rich

              #7
              Re: howto use params with insertCmd for DataAdapter?

              OK. I figured this one out so far

              Imports System.Data.Ole DB

              Man, I feel like such a helpless child right now (hate it).
              Well, now I will try your code.

              Rich

              [color=blue]
              >-----Original Message-----
              >OK. I try that. But I have one other problem. When I
              >type
              >
              >Dim cb As New OleDBCommandBui lder(...)
              >
              >it says that OleDBCommandbui lder is not defined. Do I
              >need an Imports statement? I am checking help files[/color]
              right[color=blue]
              >now.
              >
              >[color=green]
              >>-----Original Message-----
              >>Hi Rich,
              >>
              >>Normaly you do not have to do nothing to insert a new[/color]
              >row, just start typing[color=green]
              >>at the bottom.
              >>
              >>If you want it sorted have a look at the dataview, that[/color]
              >you can put between[color=green]
              >>your dataset and the datagrid.
              >>
              >>Something as dirty typed of course.
              >>\\\
              >>dim dv as new dataview(ds.tab les(0))
              >>dv.sort = "mycolumnam e"
              >>datagrid.data source = dv
              >>///
              >>Cor
              >>[color=darkred]
              >>>
              >>> Thanks for your reply. Finally got vs.net2003 loaded[/color][/color][/color]
              on[color=blue][color=green][color=darkred]
              >>> my computer.
              >>>
              >>> Question: My data is displayed in the grid control.[/color][/color]
              >The[color=green][color=darkred]
              >>> textboxes on the form are unbound textboxes. Should I
              >>> bind the textboxes to the dataset? If not, how do I
              >>> reference the textboxes, as they are the parameters I[/color][/color]
              >want[color=green][color=darkred]
              >>> to insert in the new record?
              >>>
              >>> Thanks again,
              >>> Rich
              >>>
              >>>
              >>> >-----Original Message-----
              >>> >Hi Rich,
              >>> >
              >>> >In the adonet group are some guys who hate this.
              >>> >
              >>> >But to start just do this (forget the insert, the[/color][/color]
              >update[color=green][color=darkred]
              >>> and the
              >>> >deletecomman d a while)
              >>> >
              >>> >DirectCast(Bin dingContext(ds. tables(0)),
              >>> CurrencyManager ).EndCurrentEdi t()
              >>> >Dim da As New OleDbDataAdapte r
              >>> ("OriginalSelec tString",connec tion)
              >>> >Dim cb As New OleDbCommandBui lder(da)
              >>> >If ds.HasChanges Then
              >>> > da.Update(ds)
              >>> >End If
              >>> >
              >>> >With difficult select strings the commandbuilder can[/color][/color]
              >give[color=green][color=darkred]
              >>> errors.
              >>> >
              >>> >You can probably forgot that da and replace it in the
              >>> commandbuilder with
              >>> >da1
              >>> >
              >>> >I hope this helps?
              >>> >
              >>> >Cor
              >>> >>
              >>> >> Just starting out with .net. I have a vb.net app[/color][/color]
              >where[color=green][color=darkred]
              >>> I
              >>> >> connect to an Access mdb. I use a connection[/color][/color]
              >component[color=green][color=darkred]
              >>> >> from the tool box (conn1), a data adapter component[/color][/color]
              >from[color=green][color=darkred]
              >>> >> the toolbox (da1) and create a typed dataset (ds1)[/color][/color]
              >and[color=green][color=darkred]
              >>> >> populate a grid on a form (grd1). This all works[/color][/color]
              >fine[color=green][color=darkred]
              >>> and
              >>> >> I can see data from the Access mdb in the grid. But
              >>> now I
              >>> >> want to add a record to the mdb.
              >>> >>
              >>> >> In the data adapter da1 I see in the property sheet[/color][/color][/color]
              a[color=blue][color=green][color=darkred]
              >>> >> select command (selcmd1), insert command (insCmd1)[/color][/color]
              >and[color=green][color=darkred]
              >>> >> delete command. For insCmd1 I set the connection to
              >>> >> conn1. Then I want to set the parameters. I have 3
              >>> >> fields in the Access table, fld1 (text), fld2[/color][/color]
              >(number),[color=green][color=darkred]
              >>> >> fld3 (date). In the Paramters dialog box of da1 for
              >>> >> insCmd1 I see a "Source Column" field, a "Value"[/color][/color]
              >field[color=green][color=darkred]
              >>> and
              >>> >> a "Parameter Name" field. On my vb form I have 3
              >>> >> textboxes, txt1, txt2, txt3. I want parm1 to have[/color][/color]
              >the[color=green][color=darkred]
              >>> >> value in txt1, parm2 has value for txt2, parm3 for[/color][/color]
              >txt3.[color=green][color=darkred]
              >>> >> Question: what do I put in the "Source Column[/color][/color][/color]
              field"[color=blue][color=green][color=darkred]
              >>> for
              >>> >> parm1? How do I tell it to retrieve the value of
              >>> >> txt1.text? and so on.
              >>> >>
              >>> >> Then I have a button (btn1) on the form which I[/color][/color]
              >click to[color=green][color=darkred]
              >>> >> carry out the insert operation. I am not clear on[/color][/color]
              >the[color=green][color=darkred]
              >>> >> syntax for carrying this out. Do I still have to[/color][/color][/color]
              say[color=blue][color=green][color=darkred]
              >>> >> insCmd1.Paramte rs.Add(txt1)
              >>> >> ...
              >>> >> da1.SelectCmd = insCmd1
              >>> >> da1.InsertComma nd = insCmd1.somethi ng
              >>> >>
              >>> >> Well, this is what I tried without any success. Any
              >>> >> advice how to do this would be greatly appreciated.
              >>> >>
              >>> >
              >>> >
              >>> >.
              >>> >[/color]
              >>
              >>
              >>.
              >>[/color]
              >.
              >[/color]

              Comment

              • Rich

                #8
                howto use insertCmd for DataAdapter?

                Hello,

                Cor, if you are still reading this thread, I decided to
                try something simpler because I could not understand your
                last explanation.

                Private Sub btn1_click(...)
                Dim cmd As New OleDBCommand("I nsert Into tbl1(fld1) Values
                ('test')")
                da1.InsertComma nd = cmd
                da1.Update(ds1)
                End Sub

                But this does not work either. Nothing happens. No
                error, nothing. May I ask if you could explain how to
                make the OleDBCommand object perform the insert operation?

                Thanks,
                Rich



                [color=blue]
                >-----Original Message-----
                >Greetings,
                >
                >Just starting out with .net. I have a vb.net app where I
                >connect to an Access mdb. I use a connection component
                >from the tool box (conn1), a data adapter component from
                >the toolbox (da1) and create a typed dataset (ds1) and
                >populate a grid on a form (grd1). This all works fine[/color]
                and[color=blue]
                >I can see data from the Access mdb in the grid. But now[/color]
                I[color=blue]
                >want to add a record to the mdb.
                >
                >In the data adapter da1 I see in the property sheet a
                >select command (selcmd1), insert command (insCmd1) and
                >delete command. For insCmd1 I set the connection to
                >conn1. Then I want to set the parameters. I have 3
                >fields in the Access table, fld1 (text), fld2 (number),
                >fld3 (date). In the Paramters dialog box of da1 for
                >insCmd1 I see a "Source Column" field, a "Value" field[/color]
                and[color=blue]
                >a "Parameter Name" field. On my vb form I have 3
                >textboxes, txt1, txt2, txt3. I want parm1 to have the
                >value in txt1, parm2 has value for txt2, parm3 for txt3.
                >Question: what do I put in the "Source Column field" for
                >parm1? How do I tell it to retrieve the value of
                >txt1.text? and so on.
                >
                >Then I have a button (btn1) on the form which I click to
                >carry out the insert operation. I am not clear on the
                >syntax for carrying this out. Do I still have to say
                >insCmd1.Paramt ers.Add(txt1)
                >....
                >da1.SelectCm d = insCmd1
                >da1.InsertComm and = insCmd1.somethi ng
                >
                >Well, this is what I tried without any success. Any
                >advice how to do this would be greatly appreciated.
                >
                >Thanks,
                >Rich
                >.
                >[/color]

                Comment

                • Rich

                  #9
                  howto use insertCmd for DataAdapter?

                  OK. I figured this out (sort of)

                  Private Sub btn1(...)
                  Dim cb As New OleDbCommandBui lder(da1)
                  Dim dRow As DataRow = ds1.Tables(0).N ewRow
                  dRow("fld1") = "test"
                  ds1.Tables(0).R ows.Add(dRow)
                  da1.Update(ds1)
                  End Sub

                  [color=blue]
                  >-----Original Message-----
                  >Hello,
                  >
                  >Cor, if you are still reading this thread, I decided to
                  >try something simpler because I could not understand your
                  >last explanation.
                  >
                  >Private Sub btn1_click(...)
                  >Dim cmd As New OleDBCommand("I nsert Into tbl1(fld1) Values
                  >('test')")
                  >da1.InsertComm and = cmd
                  >da1.Update(ds1 )
                  >End Sub
                  >
                  >But this does not work either. Nothing happens. No
                  >error, nothing. May I ask if you could explain how to
                  >make the OleDBCommand object perform the insert operation?
                  >
                  >Thanks,
                  >Rich
                  >
                  >
                  >
                  >[color=green]
                  >>-----Original Message-----
                  >>Greetings,
                  >>
                  >>Just starting out with .net. I have a vb.net app where[/color][/color]
                  I[color=blue][color=green]
                  >>connect to an Access mdb. I use a connection component
                  >>from the tool box (conn1), a data adapter component from
                  >>the toolbox (da1) and create a typed dataset (ds1) and
                  >>populate a grid on a form (grd1). This all works fine[/color]
                  >and[color=green]
                  >>I can see data from the Access mdb in the grid. But now[/color]
                  >I[color=green]
                  >>want to add a record to the mdb.
                  >>
                  >>In the data adapter da1 I see in the property sheet a
                  >>select command (selcmd1), insert command (insCmd1) and
                  >>delete command. For insCmd1 I set the connection to
                  >>conn1. Then I want to set the parameters. I have 3
                  >>fields in the Access table, fld1 (text), fld2 (number),
                  >>fld3 (date). In the Paramters dialog box of da1 for
                  >>insCmd1 I see a "Source Column" field, a "Value" field[/color]
                  >and[color=green]
                  >>a "Parameter Name" field. On my vb form I have 3
                  >>textboxes, txt1, txt2, txt3. I want parm1 to have the
                  >>value in txt1, parm2 has value for txt2, parm3 for[/color][/color]
                  txt3.[color=blue][color=green]
                  >>Question: what do I put in the "Source Column field"[/color][/color]
                  for[color=blue][color=green]
                  >>parm1? How do I tell it to retrieve the value of
                  >>txt1.text? and so on.
                  >>
                  >>Then I have a button (btn1) on the form which I click to
                  >>carry out the insert operation. I am not clear on the
                  >>syntax for carrying this out. Do I still have to say
                  >>insCmd1.Param ters.Add(txt1)
                  >>....
                  >>da1.SelectC md = insCmd1
                  >>da1.InsertCom mand = insCmd1.somethi ng
                  >>
                  >>Well, this is what I tried without any success. Any
                  >>advice how to do this would be greatly appreciated.
                  >>
                  >>Thanks,
                  >>Rich
                  >>.
                  >>[/color]
                  >.
                  >[/color]

                  Comment

                  • Cor

                    #10
                    Re: howto use insertCmd for DataAdapter?

                    Hi Rich,

                    This should work, but this is direct in the dataset, not using the grid,
                    My thougth is take the first sample again and do not forget that
                    endcurentedit before the update.
                    (Did you check your datagrid is not read only or something, normaly you can
                    edit direct with the you code and the code I did supply you)

                    That "has changes" is a nice command.
                    1. to debug you see if all worked fine
                    2. it does only a trip to your database if there are changes (and access is
                    not the fastest)

                    Cor[color=blue]
                    >
                    > Private Sub btn1(...)
                    > Dim cb As New OleDbCommandBui lder(da1)
                    > Dim dRow As DataRow = ds1.Tables(0).N ewRow
                    > dRow("fld1") = "test"
                    > ds1.Tables(0).R ows.Add(dRow)
                    > da1.Update(ds1)
                    > End Sub[/color]


                    Comment

                    • Topher Struggles too

                      #11
                      Re: howto use params with insertCmd for DataAdapter?

                      Did you ever get this to work? If so how? I am having a similiar problem.

                      Comment

                      Working...