I wish to import Excel data into a SQL Server table. The field values are EmpId (int), Name (varchar), Dept_Id (int), isSupervisor (bit). I am using ASP.NET MVC.
The code shown here is what I have tried so far:
private final GetEmployeeFromExcelRow(DataRow row)
{
return new final
{
EmpId = int.Parse(row[0].ToString()),
Name = row[1].ToString(),
Dept_Id = int.Parse(row[2].ToString()),
isSupervisor = Convert.ToBoolean(row[3].ToString())
};
}
I keep getting an error
String was not recognized as a valid Boolean.
I have tried inserting values as "True", True and well as 1. I am new to coding in ASP.NET MVC and this is my first question posted here, any help would be appreciated.
That is because
Convert.ToBoolean() will expect only `True` or `False`.
These are the scenarios on the boolean.
"True" (String) = true
"False" (String) = false
"0" (String) = false
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.