Solved

CheckBoxList control

Posted on 2010-09-13
8
570 Views
Last Modified: 2012-05-10
Hello,

I need to update multiple values in my DB using my CheckBoxList control. Please see my code below but i'm having a red line under the word "parameter".


                  foreach (ListItem item in cblTests.Items) {
                        if (item.Selected) {
                              cmdInsertStudentTests.Parameters("@testid").Value = item.Value;
                              cmdInsertStudentTests.ExecuteNonQuery();
                        }
0
Comment
Question by:asp_net2
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33668332
cmdInsertStudentTests.Parameters["@testid"].Value = item.Value; // change to square brackets
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 33669059
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 33669064
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 13

Expert Comment

by:Naman Goel
ID: 33669151
Hi
what is your parameter data type here is the code I am assuming parameter @testid is string(VarChar) and size as 50
 foreach (ListItem item in cblTests.Items) {
                        if (item.Selected) {
                              cmdInsertStudentTests.Parameters("@testid",SqlDbType.VarChar, 50, "testid");
.Value = item.Value.ToString();
                              cmdInsertStudentTests.ExecuteNonQuery();
                        }  
 http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.aspx
or you can use
Parameters.AddWithValue() method.
foreach (ListItem item in cblTests.Items) {
                        if (item.Selected) {
                              cmdInsertStudentTests.Parameters.AddWithValue("@testid",item.Value.ToString());
                              cmdInsertStudentTests.ExecuteNonQuery();
                        }  
 
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx 
 
0
 
LVL 4

Author Comment

by:asp_net2
ID: 33671730
the code below did not work. It had a "red line" under the word parameters saying "Non invocable member 'System.Data.SqlClient.SqlCommand.Parameters' cannot be used like a method.


            foreach (ListItem item in cblTests.Items) {
                       if (item.Selected) {
                             cmdInsertStudentTests.Parameters("@testid",SqlDbType.VarChar, 50, "testid").Value = item.Value.ToString();
                             cmdInsertStudentTests.ExecuteNonQuery();
                       }  
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 33671755
foreach (ListItem item in cblTests.Items) {
                       if (item.Selected) {
                             cmdInsertStudentTests.Parameters["@testid"].Value = item.Value.ToString();
                             cmdInsertStudentTests.ExecuteNonQuery();
                       }  
0
 
LVL 4

Author Closing Comment

by:asp_net2
ID: 33671770
Thank you for ALL your help. That worked out as I needed.
0
 
LVL 13

Expert Comment

by:Naman Goel
ID: 33672506
Hey asp_net2,

Good to know that accepted solution is exactly same as solution suggested by me..


0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

810 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