Professional Web Applications Themes

How would I insert multiple rows of data from one form? - ASP.NET General

Dear ASP.NETers, How would I insert multiple rows of data from a web form? Are there any tute's and stuff around. Couldn't find any myself. Thanks in advance. SSP...

  1. #1

    Default How would I insert multiple rows of data from one form?

    Dear ASP.NETers,

    How would I insert multiple rows of data from a web form?

    Are there any tute's and stuff around. Couldn't find any myself.

    Thanks in advance.
    SSP


    SSP Guest

  2. #2

    Default How would I insert multiple rows of data from one form?

    Hi SSP,

    Yes, you can insert multiple rows of data from a webform.
    simply call sproc, how many number of times you want to
    insert data.

    HTH

    Ravikanth

    >-----Original Message-----
    >Dear ASP.NETers,
    >
    >How would I insert multiple rows of data from a web form?
    >
    >Are there any tute's and stuff around. Couldn't find any
    myself.
    >
    >Thanks in advance.
    >SSP
    >
    >
    >.
    >
    Ravikanth[MVP] Guest

  3. #3

    Default Re: How would I insert multiple rows of data from one form?

    Hi Ravikanth,

    I can't use sproc's unfortunately.

    I am using ACCESS 2000 database.

    Any other methods?

    SSP

    "Ravikanth[MVP]" <dvravikanthhotmail.com> wrote in message
    news:0a9d01c34b98$922d7270$a401280aphx.gbl...
    > Hi SSP,
    >
    > Yes, you can insert multiple rows of data from a webform.
    > simply call sproc, how many number of times you want to
    > insert data.
    >
    > HTH
    >
    > Ravikanth
    >
    >
    > >-----Original Message-----
    > >Dear ASP.NETers,
    > >
    > >How would I insert multiple rows of data from a web form?
    > >
    > >Are there any tute's and stuff around. Couldn't find any
    > myself.
    > >
    > >Thanks in advance.
    > >SSP
    > >
    > >
    > >.
    > >

    SSP Guest

  4. #4

    Default Re: How would I insert multiple rows of data from one form? C#

    I am half way there to figuring it out.

    So far I have managed to write the following code to insert an array into
    the database.

    Now I have to figure out how to get the relevant DataList fields into an
    array (to insert into the database). Any ideas on creating a dynamic array.

    Code:

    private void Submit1_ServerClick(object sender, System.EventArgs e)
    {
    // Create an Array
    string[,] tippings = new string[,] {{"988", "AUS", "hhhty"}, {"56678",
    "SA", "LfghghjLL"}, {"2367673", "NZ", "dfdfghgfjgfhf"}};
    // Loop through the Array and insert one by one.
    for (int i = 0; i <= tippings.Rank; i++) {
    oleDbInsertCommand2.Parameters["SomeD"].Value = tippings[i, 0];
    oleDbInsertCommand2.Parameters["SomeValue"].Value = tippings[i, 1];
    oleDbInsertCommand2.Parameters["SomeOtherValue"].Value = tippings[i, 2];
    oleDbConnection1.Open();
    oleDbInsertCommand2.ExecuteNonQuery();
    oleDbConnection1.Close();
    }
    }

    SSP

    "SSP" <sspdt.com> wrote in message
    news:OWjCbj2SDHA.2196TK2MSFTNGP12.phx.gbl...
    > Dear ASP.NETers,
    >
    > How would I insert multiple rows of data from a web form?
    >
    > Are there any tute's and stuff around. Couldn't find any myself.
    >
    > Thanks in advance.
    > SSP
    >
    >

    SSP Guest

  5. #5

    Default Re: How would I insert multiple rows of data from one form? C#

    I'm not sure if I'm answering the question you are asking, but if you need
    to create a dynamic array (to replace the static dummy array "string[,]
    tippings") that is pretty simple:

    name the all your input fields for each row the same (using a numerical
    sequence for each extra row), when you submit, use something like:

    // for loop
    string[] row = Request.Form[ strPrefix +
    iRowName.ToString() ].ToString.Split(", ");
    AddRowToDB( row );
    //end for loop

    It would be a whole lot easier to do this using a DataGrid, DataSet,
    DataAdapter, and relative Commands for the DataAdapter.

    // Mike

    "SSP" <sspdt.com> wrote in message
    news:%232maPuwTDHA.2220TK2MSFTNGP11.phx.gbl...
    > I am half way there to figuring it out.
    >
    > So far I have managed to write the following code to insert an array into
    > the database.
    >
    > Now I have to figure out how to get the relevant DataList fields into an
    > array (to insert into the database). Any ideas on creating a dynamic
    array.
    >
    > Code:
    >
    > private void Submit1_ServerClick(object sender, System.EventArgs e)
    > {
    > // Create an Array
    > string[,] tippings = new string[,] {{"988", "AUS", "hhhty"}, {"56678",
    > "SA", "LfghghjLL"}, {"2367673", "NZ", "dfdfghgfjgfhf"}};
    > // Loop through the Array and insert one by one.
    > for (int i = 0; i <= tippings.Rank; i++) {
    > oleDbInsertCommand2.Parameters["SomeD"].Value = tippings[i, 0];
    > oleDbInsertCommand2.Parameters["SomeValue"].Value = tippings[i, 1];
    > oleDbInsertCommand2.Parameters["SomeOtherValue"].Value = tippings[i,
    2];
    > oleDbConnection1.Open();
    > oleDbInsertCommand2.ExecuteNonQuery();
    > oleDbConnection1.Close();
    > }
    > }
    >
    > SSP
    >
    > "SSP" <sspdt.com> wrote in message
    > news:OWjCbj2SDHA.2196TK2MSFTNGP12.phx.gbl...
    > > Dear ASP.NETers,
    > >
    > > How would I insert multiple rows of data from a web form?
    > >
    > > Are there any tute's and stuff around. Couldn't find any myself.
    > >
    > > Thanks in advance.
    > > SSP
    > >
    > >
    >
    >

    Mike S Guest

  6. #6

    Default Re: How would I insert multiple rows of data from one form? C#

    OK I tried and I can't still manage it.

    Here's the full scenario:
    What I am building is a footy tipping (pool) competition app. What I am
    trying to do is to allow lots of people to tip the winning team from a list
    of games to be played every week. This schematic shoulf give an idea of the
    tipping form:

    Tipping Form


    Date Time Home Team Visiting Team Tie
    2 Aug, 03 7:00 PM England Fiji
    2 Aug, 03 7:00 PM Fiji Australia
    2 Aug, 03 7:00 PM New Zealand Australia






    This is the datagrid my ASPX Page:
    -------------------------------------------------------------------
    <asp:datagrid id=DataGrid1 runat="server" Width="100%"
    AutoGenerateColumns="False" DataMember="Table" DataKeyField="GameID"
    DataSource="<%# dsMatchesForTipping1 %>" ForeColor="Black" GridLines="None"
    CellPadding="2" BackColor="LightGoldenrodYellow" BorderWidth="0px"
    BorderColor="Tan">
    <Columns>
    <asp:TemplateColumn SortExpression="GameID">
    <ItemTemplate>
    <input type="hidden" runat="server" name="GameID" id="GameID" value='<%#
    DataBinder.Eval(Container.DataItem, "GameID") %>' />
    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:BoundColumn DataField="Date" SortExpression="Date" HeaderText="Date"
    DataFormatString="{0:d MMM, yy}" />
    <asp:BoundColumn DataField="Time" SortExpression="Time" HeaderText="Time"
    DataFormatString="{0:t}" />
    <asp:BoundColumn DataField="HomeTeamName" SortExpression="HomeTeamName"
    HeaderText="Home Team" />
    <asp:TemplateColumn SortExpression="HomeTeamID">
    <ItemTemplate>
    <INPUT id="radioButtonPickHomeTeam" runat="server" type="radio" value='<%#
    DataBinder.Eval(Container.DataItem, "HomeTeamID") %>' name="Pick">
    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:BoundColumn DataField="VisitingTeamName"
    SortExpression="VisitingTeamName" HeaderText="Visiting Team" />

    <asp:TemplateColumn SortExpression="VisitingTeamID">
    <ItemTemplate>
    <INPUT id="radioButtonPickVisitingTeam" runat="server" type="radio"
    value='<%# DataBinder.Eval(Container.DataItem, "VisitingTeamID") %>'
    name="Pick">
    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:TemplateColumn HeaderText="Tie">
    <ItemTemplate>
    <INPUT id="radioButtonPickTie" runat="server" type="radio" value="Tie"
    name="Pick">
    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:TemplateColumn SortExpression="UserEmail">
    <ItemTemplate>
    <input type="hidden" runat="server" name="UserEmail" id="UserEmail"
    value="sspssp.com" />
    </ItemTemplate>
    </asp:TemplateColumn>

    </Columns>
    </asp:datagrid>
    ----------------------------------------------------------------------------
    ----

    For the Code Behind Page:
    ----------------------------------------------------------------------------
    ------
    private void Submit1_ServerClick(object sender, System.EventArgs e)
    {
    string[,] tippings = new string[,] {{"988", "AUS", "hhhty"}, {"56678",
    "SA", "LfghghjLL"}, {"2367673", "NZ", "dfdfghgfjgfhf"}};

    for (int i = 0; i <= tippings.Rank; i++) {
    oleDbInsertCommand2.Parameters["GameID"].Value = tippings[i, 0];
    oleDbInsertCommand2.Parameters["Pick"].Value = tippings[i, 1];
    oleDbInsertCommand2.Parameters["Username"].Value = tippings[i, 2];
    oleDbConnection1.Open();
    oleDbInsertCommand2.ExecuteNonQuery();
    oleDbConnection1.Close();
    }
    }
    ----------------------------------------------------------------------------
    ----------

    Basically, if I am able to insert in the database the array "tippings"; then
    I should be able to dynamically populate the "tippings" array and then
    insert it into the database.

    Unfortunately I am unable to do it ;-( and time isn't on my side either.

    Any ideas?

    SSP

    "Mike S" <mikesn-o.sp-a.m.pac.odedodea.edu> wrote in message
    news:uKX372wTDHA.2188TK2MSFTNGP10.phx.gbl...
    > I'm not sure if I'm answering the question you are asking, but if you need
    > to create a dynamic array (to replace the static dummy array "string[,]
    > tippings") that is pretty simple:
    >
    > name the all your input fields for each row the same (using a numerical
    > sequence for each extra row), when you submit, use something like:
    >
    > // for loop
    > string[] row = Request.Form[ strPrefix +
    > iRowName.ToString() ].ToString.Split(", ");
    > AddRowToDB( row );
    > //end for loop
    >
    > It would be a whole lot easier to do this using a DataGrid, DataSet,
    > DataAdapter, and relative Commands for the DataAdapter.
    >
    > // Mike
    >

    SSP Guest

Similar Threads

  1. Question Insert multiple rows with dynamic data
    By gassmann56560 in forum Coldfusion - Getting Started
    Replies: 0
    Last Post: April 6th, 07:02 PM
  2. Multiple rows of data into 1 row
    By Chip Jones in forum Coldfusion Database Access
    Replies: 1
    Last Post: June 9th, 04:25 PM
  3. Getting data from multiple rows into a list
    By bika_123 in forum Coldfusion Database Access
    Replies: 2
    Last Post: December 3rd, 05:04 AM
  4. Update multiple rows on form submission
    By Efused in forum Coldfusion Database Access
    Replies: 1
    Last Post: September 12th, 07:43 PM
  5. Display 1 data row as multiple datagrid rows
    By Craig Banks in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: February 21st, 09:25 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139