views:

40

answers:

1

Hi all, While i am inserting the checkbox selected list item to the database table i am getting this error "Error converting data type nvarchar to bit" In the table i have a field called Disease with bit datatype. My motto to store the different type of disease in one field. Here is selecting checkbox item code: Pls somebody point me out where is my error or give some new idea how can i do the same in better way....

string typeofdisease = "";
foreach (ListItem li in CheckBoxListDisease.Items)
{
    if (li.Selected)
    {
        typeofdisease += li.Value;
    }
}
typeofdisease = typeofdisease.TrimEnd();
+1  A: 

You didn't mention the framework or database you are using, but I'll bet that li.value is always a string containing "Yes" or "No". As a result, you are trying to shove a string into a boolean field. You need to convert your "Yes" and "No" to 1 and 0 respectively. Or, you need to change your database column from boolean to char.

RichO
Hi I am using SQLServer 2000, VS2005
Rahul
If it's an asp.net program, then the buttons are certainly containing a "Yes"/"No" value. I ran into the same problem some time ago.
RichO