2016-12-13 3 views
0

스프레드 시트가 있고 열 중 하나가 IsActive이고 모든 값이 1 (Excel의 숫자 데이터 형식)입니다. SQL Server에서 삽입되는 테이블에는 IsActive에 대한 비트 데이터 형식이 있습니다. 그러나, 내가 오류가 때 SQL Server의 비트와 호환됩니다 Excel에서 데이터 유형이 있는가 데이터가Excel 스프레드 시트에서 SQL Server로 비트 유형 가져 오기

The given value of type String from the data source cannot be converted to type bit of the specified target column. 

입니다 삽입하려고?

excelConnection.Open(); 
        using (OleDbDataReader dReader = cmd.ExecuteReader()) 
        { 
         using (SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection)) 
         { 
          //Give your Destination table name 
          sqlBulk.DestinationTableName = "Medicine"; 
          sqlBulk.WriteToServer(dReader); 
         } 
        } 

편집 : 여기에 내가 분명히 문자열이 isActive 조금 컬럼에 삽입하지 않으 OLEDB를 명령

using (OleDbCommand cmd = new OleDbCommand("Select ...[IsActive]... from [Sheet1$]", excelConnection) 

입니다.

+0

열 이름 IsActive가 문자열로 선택 되었습니까? –

+0

나는 그렇게 생각할 것이다. 명시 적으로 비트 또는 부울로 변환 해 보라. – Anand

답변

0
using (OleDbCommand cmd = new OleDbCommand("Select ...CAST(COALESCE([IsActive], 0) AS BIT)... from [Sheet1$]", excelConnection)