Solved

CheckBoxList control

Posted on 2010-09-13
8
442 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

18 Experts available now in Live!

Get 1:1 Help Now