Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CheckBoxList control

Posted on 2010-09-13
8
Medium Priority
?
577 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

886 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