问题
I've been trying to figure out for a long time now how to create an interface that can allows users to input several rows of data and pass those entries into an SQL server database all in one shot. I could not get any better ideas so I came up with this (see picture below).

What I envisioned is that the user enters values in the textboxes and hits the "add to list" button. The values are then populated in the list box below with the heading "exhibits lists" and when the add exhibit button is pressed, all values from the list box are passed into the database.
Well, I'm left wondering again if it would be possible to tie these values from the textboxes to the list box and whether I'd be able to pass them into the database.
If it were possible then I'd please love to know how to go about it otherwise I'd be glad if you could recommend a better way for me to handle the situation otherwise I'd have to resolve to data entry one at a time.
I believe there is some useful information from this website that can help solve my problem but I just can't make heads or tails of the article... it seems like I'm almost there and it skids off. Can everyone please read and help me adapt it to my situation? Post below:
http://www.codeproject.com/KB/aspnet/ExtendedGridView.aspx
回答1:
Yes, it is possible. I have done this twice before.
Check out the "Data Access Tutorials" at http://www.asp.net/web-forms/data for ideas.
Overview
- For the user-interface, you want a data-entry-form above a data-grid.
- For the back-end, you want a data-adapter (or table-adapter) that loads and saves data to the database in one operation.
You would use a DataSet
and DataAdapter
to update the database, and manipulate a DataRow
for the input and a DataTable
for the list-box. Note the list-box is actually a data-grid, repeater, or other control that accepts a DataTable
as a DataSource
.
The
DataAdapter
fills theDataSet
which contains theDataTable
.The input controls bind to a
DataRow
created from theDataTable
. When the user clicks add-to-list, you add the data-row to the data-table, then create a new data-row for the next item.When the user clicks add-exhibit, it is a simple matter of using the
DataAdapter
to update the database. Any changed, deleted, and added data is handled for you.
回答2:
You could use a transaction to encapsulate all the sql queries you are trying to run, so you can then just 'commit' the transaction in one to the database? Are you still having difficulty with this issue?
来源:https://stackoverflow.com/questions/4682619/what-are-the-possibilities-of-displaying-items-in-a-listbox