?
Solved

Update Access with C# .NET, using OleDbCommand Parameters to Pass Checkbox Value

Posted on 2004-11-01
18
Medium Priority
?
5,256 Views
Last Modified: 2008-02-07
I figure this is simple but I can't find the answer...I am updating an access database using ASP.NET C#.  The form has several check box controls that I want to update in the DB.  I am not sure how to create the OleDbCommand parameters for checkbox.  I think access checkbox values are -1, 0, and NULL but I can't figure out how to specify the datatype (if it is even necessary) and the parameter in the UPDATE Statement.

void updateRecord(Object Source, EventArgs E){
      //set connetction objects
      OleDbConnection objConn = new OleDbConnection(strConnection);
      OleDbCommand objCmd;
      OleDbDataReader objRdr;
      objCmd = new OleDbCommand("UPDATE omniforms SET name=@name, new=@newStatus, dayNight=@dayNight, billingStatus=@billingStatus, signatureStatus=@signatureStatus WHERE " + Request.QueryString["id"] + "", objConn);
      objCmd.Parameters.Add("@name", txtName.Text);
      objCmd.Parameters.Add("@newStatus", ddlNewStatus.SelectedItem.Value);
       objCmd.Parameters.DbType("@dayNight", ??????);  //checkbox named chkDayNight
      objCmd.Parameters.Add("@billingStatus", ddlBillingStatus.SelectedItem.Value);
      objCmd.Parameters.Add("@signatureStatus", ddlSignatureStatus.SelectedItem.Value);                  
      objConn.Open();
      objCmd.ExecuteNonQuery();
      objConn.Close();
}
0
Comment
Question by:drliebs
  • 10
  • 7
17 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12464336
Access should be looking for True/false or Yes/No depending on how you set it up.

0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12464342
you may be able to pass the index, but it is not neccesary.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12464367
I usually handle it with something like this
 If Me.cbNewsletter.Checked Then
                    Session("Newsletter") = "True"
                End If

where cbNewsletter is my checkbox
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 17

Expert Comment

by:AerosSaga
ID: 12464375
and no you don't have to specify a datatype
0
 

Author Comment

by:drliebs
ID: 12465017
Can you fill in the blank or write out the correct code?

objCmd.Parameters.DbType("@dayNight", ??????);  //checkbox named chkDayNight
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 100 total points
ID: 12465340
If Me.chkDayNight.Checked Then
                    Session("DayNight") = "True" ' or yes if you defined it that way
                Else
Session("DayNight") = "False" ' or no if you defined it that way
                End If

objCmd.Parameters.DbType("@dayNight", Session("DayNight"));  //checkbox named chkDayNight

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12494915
Why did I get a 'C'?  Did you have any further questions?  Since you did not post them I am assuming no, and ask that you change my grade.

Aeros
0
 

Author Comment

by:drliebs
ID: 12495000
Thanks, I ended up doing something a little different but you got me in the right direction, this is the C# code I ended up using

      if (chkDayNight.Checked){
      objCmd.Parameters.Add("@dayNight", true);
      }
      else{
      objCmd.Parameters.Add("@dayNight", false);      
      }
0
 

Author Comment

by:drliebs
ID: 12495019
I asked for C# code, I don't see any reason to use a variable and the code you posted was giving me errors.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12495045
I would have clarified or attempted to help if you had asked.
0
 

Author Comment

by:drliebs
ID: 12495074
I don't mean to sound rude and I don't mean for a "C" grade to belittle you or effect your score, but the choice was "average" and I thought it was an average answer, an exceptional answer would have been more complete.  Thank you again, I hope that others will find the thread usefull.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12495087
Ask 10 Experts this question, and you'll get 10 different answers. One thing is certain: Grading at Experts Exchange is NOT like school. Here's what EE says:

    Although we use an A-D scale here at Experts Exchange, it works differently than, say, school grades. If one or more Experts' proposals are accepted as answers, they should usually be given an A or B grade, since they have taken the time to provide you with a working solution. If a possible solution is incomplete - ask for clarification or details before accepting the answer and grading it. People should not be given lower grades because of incorrect grammar or because you just accepted their answer or comment to close the question. Keep in mind, your question and any follow-up comments should be focused so that there can be a specific answer. The following is a good guideline to follow when grading:

        * A: The Expert(s) either provided you with a thorough answer or they provided you with a link to information that thoroughly answered your question. An "A" can also be given to any answer that you found informative or enlightening beyond the direct question that you asked.
        * B: The Expert(s) provided an acceptable solution, or a link to an acceptable solution, that you were able to use, although you may have needed a bit more information to complete the task.
        * C: Because Experts' reliability are often judged by their grading records, many Experts would like the opportunity to clarify if you have questions about their solutions. If you have given the Expert(s) ample time to respond to your clarification posts and you have responded to each of their posts providing requested information; or if the answers, after clarification, lack finality or do not completely address the issue presented, then a "C" grade is an option. You also have the option here of just asking Community Support to delete the question.

    Remember, the Expert helping you today is probably going to be helping you next time you post a question. Give them a fair chance to earn an 'Excellent!' grade and they'll provide you with some amazing support. It's also true that a "C" is the lowest grade you can give, and the Experts know that -- so use it judiciously.

Only the Moderators and Page Editors have the choice to give a D grade. Beyond that, in a practical sense, the grading guidelines have "softened" a bit over the last year or two; one might expect that the majority of grades would be Bs (a standard "bell" curve), but the fact is that the culture of the site has caused there to be an inordinately high percentage of As. The Moderators have been instructed to ensure that the As they award are actually "Excellent" answers. Similarly, the C grade is the lowest that can be given by a member, a fact which should be kept in mind when grading as well.

The use of a C in a vindictive manner is likely to be changed by a Moderator. You may not like the answer you get, and in some cases, and you may not like the way it is delivered, but if it is deemed to be accurate, no less than a B is an acceptable grade.
0
 

Author Comment

by:drliebs
ID: 12495120
Your post was fast, I can't always count on that and I was able to figure it out easy enough.  Does a "C" make you look bad on this forum? I will change it to a B if that is what you are concerned about.  I appreciated the help, I really do.
0
 

Author Comment

by:drliebs
ID: 12495145
With that in mind I appologize and a B would be more appropriate...now how do I correct this?
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12495155
Yes it does, and I was more than willing to help.  I understand that you feel it was not the best answer, but since you did not ask for further help or clarification I request you post a message here and asked for the grade to be changed to a B.

http://www.experts-exchange.com/Community_Support/askQuestion.jsp
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12495339
Thank you so much my friend.

Aeros
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses

588 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