Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
krishnet
Starting Member
29 Posts |
Posted - 2007-05-29 : 08:44:07
|
Hi frdz, I m using the following code for the multiple list-box selection option control. I m using ASP.NET with C# 2005. The following code on selection of the submit button should insert data into database and display into the Gridview. But it fails to insert the multiple selected values.It displays the first value selected from the listbox (if 3values are selected then it displays 3times the first value only into the database when i remove primary key else it inserts only 1 time with primary key). Can anyone rectify what's wrong over here in my code.It displays correctly in the label if i put it on the form.It is not inserted with the help of sqldatasource. protected void cmdsubmit_Click(object sender, EventArgs e) { SqlDataSource1.InsertParameters["productname"].DefaultValue = tbproductname.Text; foreach (ListItem item in listboxcompany.Items) { if (item.Selected) { // Label1.Text += "<li>" + item.Text; SqlDataSource1.InsertParameters["companyname"].DefaultValue = listboxcompany.SelectedItem.ToString(); SqlDataSource1.Insert(); } } GridView1.Visible=true; } Here the one productname can contain the name of different companyname according to my requirement.ProductId ProductName Companyname1 A A A B A C Thanxs in adv.Here the productId contains the identity field.Also,pls tell me how can we retrieve the values into listbox thru database of sqlserver 2005 ? Please help me...... |
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2007-05-29 : 10:31:05
|
does it throwing any error? rather u specify, its not inserting values into table means what eaxctly happening?thanks,Mahesh |
|
|
cvraghu
Posting Yak Master
187 Posts |
Posted - 2007-05-29 : 12:58:14
|
Why are you getting the ID column value from tbProdcutId.Text and not from list box? Why assignment of ID is not within the loop?My wild guess is that the code inserts the same ID three times. Provide the table structure and relation to UI, to get better answers. |
|
|
krishnet
Starting Member
29 Posts |
Posted - 2007-05-29 : 13:05:06
|
I mentioned earlier but anyways,It does not throws any error when above code is written.(1)I want the following values as a output ::ProductID (p.k.) companynameidentityfield 1 A B C (2)I get the output as follows which i don't want ::ProductID (p.k.) companynameidentityfield 1 A(3)Then if i remove the P.K. then it gives the following output ::ProductID companyname 1 A 1 B 1 C I want the output as (1) but i get it as (2) and (3) if i do changes..Hope this is enough to solve my problem.. |
|
|
krishnet
Starting Member
29 Posts |
Posted - 2007-05-29 : 13:07:54
|
I m joining the two tables at the time of insert..table:1companyid companynametable:2productidcompanyidproductname |
|
|
krishnet
Starting Member
29 Posts |
Posted - 2007-05-30 : 03:18:24
|
Any reply to do this ??I want the data as to be inserted:I m using the listbox for the table:2 where companyid is the foreign key and productid is primary key.productid companyname productname1 A z1 B z1 C z2 F y2 A y2 D y Please tell me how can i perform it ??Do any changes needed ?? |
|
|
hammerock_011
Starting Member
1 Post |
Posted - 2007-06-05 : 22:16:49
|
i have also problem in ListBox multiple insert. I want to insert for example 3 items in my table item 1, 2 and 3. but the problem is it on insert one row but i selected 3 items on my listbox. HOw can i do that?Please Help me..ThanksBernie Leynes |
|
|
|
|
|