Click here to Skip to main content
15,662,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my database i have some fields which is already filled with Yes or No like. A field Medical is filled with value "Yes" or "No" at the back end in data base while on the form there are some fields with check boxes like a check box against the medical label and if it is checked means medical allowance is granted to that particular person else not, now i want to show the data on the form with the help of that check box if it is yes in data base how i check the check box of the form.
while i am using such codes.

What I have tried:

if Rs("Medical").Value = "Yes" Or "yes" Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
Posted
Updated 2-Jan-17 1:45am
Comments
Michael_Davies 2-Jan-17 6:46am    
Pretty sure that Checkbox.Checked accepts "Yes" as true and "No" as false so you can directly assign the value:

CheckBox1.Checked = Rs("Medical").Value
Saadbinata 2-Jan-17 7:11am    
If Rs("Medical").Value = "yes" Then
CheckBox1.Checked = Rs("Medical").Value
Else
CheckBox1.Checked = False
End If

by using such format it didn't show any error but it also didn't showing in checkbox checked. nothing happening.
Peter Leow 2-Jan-17 6:55am    
You are not even sure if "Yes" or "yes"? You should find out what the actual values are captured in the database table first.
Saadbinata 2-Jan-17 7:05am    
I am using "Yes" or "yes" because in the database some are found in "Yes" form and some are found in "yes" format. means the data entry operator entered in such format. and i am new to vb.net
Dave Kreskowiak 2-Jan-17 11:00am    
Apparently you're also new to validation of data. You NEVER put unvalidated data into the database in the format you are now allowing. What if the user entered "YEs"? Your code has already failed.

If the field is only allowed to have a Yes or No value, that maps directly to a boolean value which can only have true or false. You should have processed and mapped that Yes or No to a boolean true/false and stored that instead. I don't know why you're allowing a user to manually type Yes or No when it would have been more appropriate to use a dropdown list.

you could also write :
VB
CheckBox1.Checked = (Rs("Medical").Value.toString.toLower = "yes") 


Was this your Problem ...?
 
Share this answer
 
v2
Comments
Saadbinata 2-Jan-17 7:28am    
If Rs("Medical").Value = "yes" Then
CheckBox1.Checked = (Rs("Medical").Value.toLower = "yes")
Else
CheckBox1.Checked = False
End If

Sir, Its also not working,
I need to show the value of the field Medical in database which is yes and i need to show this value as on the check box in checked form.
Saadbinata 2-Jan-17 8:52am    
If CheckBox1.Checked = (Rs("Medical").Value.ToString.ToLower = "yes") Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If

it also showing that checkbox in checked form which values are "no" in database. what will do for that
Saadbinata 2-Jan-17 9:08am    
Respected Sir Ralf Meier. Thank you for your response now i set my code like this with you help and it is working properly.

If Rs("Medical").Value.ToString.Trim = "yes" Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If

Thanks once again.
Ralf Meier 2-Jan-17 9:50am    
It is good if it works ... but the code from my Solution must work also - exactly coded like I have written.

Perhaps you take a look on it once more ... and look with the Debugger if something goes wrong and if Yes : what goes wrong. Then we both could pass this error.
But only if you want ;)
Instead of
if Rs("Medical").Value = "Yes" Or "yes" Then
it should be
If Rs("Medical").Value = "Yes" Or Rs("Medical").Value = "yes" Then

If possible, you should clean up the database.
Minimally, try to look for that script that is responsible for inserting such vague values and make it right.
Good luck.
+++++[round 2]+++++
Based on your feedback, it is entered by some data entry staff in free text form, then good luck to your, it may turn out to be "YES", "    yes", "yes    ", ...etc. You got it?
In such cases, you can trim the value and see how it turns out:
Rs("Medical").Value.Trim()

The last resort, in fact, it should be the very first, check the value of Rs("Medical").Value through Visual Basic .NET Debugging[^].
 
Share this answer
 
v4
Comments
Saadbinata 2-Jan-17 7:53am    
If Rs("Medical").Value = "Yes" Or Rs("Medical").Value = "yes" Then

it also having the same result.
it is not possible to clear the database. because my boss kick men off from my job
Saadbinata 2-Jan-17 9:10am    
thanks for your support to solving my problem now i have such a code which was solved my problem
If Rs("Medical").Value.ToString.Trim = "yes" Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
your clue is adding in my code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900