Solved

CheckBoxList control

Posted on 2010-09-13
8
572 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 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