Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-11-01
18
Medium Priority
?
5,247 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
[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
  • 10
  • 7
18 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help 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

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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