Solved

Please Explain | Verify | Confirm....

Posted on 2004-09-29
9
205 Views
Last Modified: 2010-04-15
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
Comment
Question by:TMF123
9 Comments
 
LVL 15

Accepted Solution

by:
praneetha earned 250 total points
ID: 12183676
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
 

Expert Comment

by:yanzickp
ID: 12186881
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
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 250 total points
ID: 12188429
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:TMF123
ID: 12190017
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
 

Author Comment

by:TMF123
ID: 12192584
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
 
LVL 15

Expert Comment

by:praneetha
ID: 12192928
you just have to do it some button click or something
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question