Solved

Please Explain | Verify | Confirm....

Posted on 2004-09-29
9
197 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now