• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Please Explain | Verify | Confirm....

I really need help.  

I have to build a web application in c# where there are several controls (such as listbox controls) that will post multiple selections to a database.  My frustration is in the fact that I cannot find any documentation that demonstrates how to accomplish this.  All the documentation I have located shows you how to build a manual array list to populate the control and then after clicking a button, display those items selected in a label control.  WOW!!!!!

My question is, what do you do (or use) when you want to trap multiple selections from a control (like the listbox) and post them to a database?

Here is an example of an webform that encompasses my scenario:
Webform:
Name of Car:[textbox]
Users of Car:[listbox or family members]

I need to be able to store the values of the listbox selected so that I can at any point run a query against this column to find out which car or what cars family member 3 drives.

I figure there are many e-com sites out there that emplore this functionality, I just can't find an example of the code.

Thank you for your patience in reading this.

Sincerely,
Tim
0
TMF123
Asked:
TMF123
2 Solutions
 
praneethaCommented:
after they select the family memebers from a list and click submit button

at the button click you can write a sql statement to store it in database / use a stored procedure...

http://www.c-sharpcorner.com/Database.asp

good luck
0
 
yanzickpCommented:
I haven't tried it, but you should be able to utilize a data set and update the data set programatically based on what items in the list are selected.

One way that I did something similar was using a data grid with a select/remove button...  
0
 
123654789987Commented:
Maintain a datatable.

DataTable dtCar = new DataTable();
dtCar.Columns.Add("CarName");
dtCar.Columns.Add("CarUser");

Store the information u have in this format in the

DataRow dr = dtCar.NewRow();
dr[0] = "Car1";
dr[1] = "Uses1";
dtCar.Rows.Add(dr);

U can use this database to same the information about a car and its users. when u have to update the user u can get the inforamtion from this datatable and insert the record in the database.

OracleConnection myConnection = new OracleConnection(myConnectionString);
OracleCommand myCommand = new OracleCommand(myExecuteQuery, myConnection);
myCommand.Connection.Open();

for(int i = 0 ; i < = dtCar.Rows.Count -1 ; dtCar++)
{
  myExecuteQuery= "Insert into Car(Carname, CarUser) values ('" + dtCar.Rows[i][0] + "', '" + dtCar.Rows[i][1] + "') "

     myCommand.ExecuteNonQuery();
 }

myConnection.Close();


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TMF123Author Commented:
Ok, sounds feasible.  However, what if the complexity of the scenario increases such as this:

What if 3/4 of the data from the web form is going to be submitted to one table and all of the listbox controls values submited to other tables.  All at the same time when the user hits submit.

Questions:
How are you able to get the ID value from the main table to submit into the other tables used for the listbox control values?  Do you need to script the SQL in such as a way that the data is submitted into the main table first then the others?

I assume you would need to produce a datatable for each listbox control you have in your webform that has the proprerty set for multiple select?

Thank you for your help.

Regards,

Tim
0
 
TMF123Author Commented:
One of the things I don't understand is how does the datatable know where to get the data from? Where do you plug-in the control for the listbox?
0
 
praneethaCommented:
you just have to do it some button click or something
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now