Can anyone help in converting string value in C# to bit equivalent in Sql. I'm trying to bulkcopy the values of a datatable into Sql table. All the values I've in the datatable are in string format. When I try to bulkcopy to SQL table I'm getting an error for bit datatype columns.Can anyone please post the C# code to convert string to bit type before I bulkcopy to SQL table.
If your strings are "true" and "false" (ignoring case and whitespace) this will work:
bool bit = bool.Parse(str);
If your strings are something else, you could use:
bool bit = !string.IsNullOrEmpty(str) && (str=='Y' || str=='y' || str=='T' || str=='t' || str=='1');
SQL wants a bool value.