I have a text box where I introduce a number and a button named Add which introduce the number in the list box. After adding all the numbers wanted when I click on a button Finalize to add what is in the list box in database.
My database table is Number with ID IDnumber NAME
.
IDnumber
= when I add multiple numbers from list box in database I want that all numbers have the same ID.
For example in my list I have
- 45341
- 5466
- 4646
- 464
and in my database to have
ID IDnumber NAME
1 1 45341
1 1 5466
1 1 4646
1 1 464
And the next time I will add from list box , the next number will have the IDnumber
2.
<asp:TextBox ID="txtNrShipment" runat="server" Height="16px" Width="100px"></asp:TextBox>
<asp:Button ID="btnAddSO" runat="server" Text="Add" OnClick="btnAddSO_Click" CausesValidation="False" />
<asp:ListBox ID="ListBoxSO" runat="server">
</asp:ListBox>
<asp:Button ID="btnFinalizeSO" runat="server" Text="Finalize" OnClick="btnFinalizeSO_Click" />
protected void btnAddSO_Click(object sender, EventArgs e)
{
ListBoxSO.Items.Add(txtNrShipment.Text);
txtNrShipment.Text = " ";
}
You have not provided the actual code of btnFinalizeSO's click event. If you do not have it yet, the first step you must implement is the connection to your database, for example with Entity Framework. If you connect with Entity Framework you could create objects of your table from the database to inject them to the db. For example:
This is more or less what you need. May be it is good to catch exceptions.