?
Solved

CheckBoxList control

Posted on 2010-09-13
8
Medium Priority
?
575 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

719 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