开发者

How to fix error in exporting Excel data to SQL Server database?

开发者 https://www.devze.com 2023-01-07 23:55 出处:网络
Cannot inse开发者_如何学Gort the value null into column \'COLUMN1\',table\'DB1.dbo.table1\';Column

Cannot inse开发者_如何学Gort the value null into column 'COLUMN1',table'DB1.dbo.table1';Column does not allow nulls. Insert fails.the statement has been terminated.

This always shows if edit or save another data onto excel columns.

 using (SqlCommand cmd = new SqlCommand("Insert into dbo.Table1 Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database="+ filepath + ";HDR=YES','SELECT * FROM [Sheet1$]')", conn))

Is there a best way to handle this....


Did you try an SQL Statement like this:

INSERT INTO Table1 SELECT ISNULL(YourColumn, GETDATE()) FROM OPENROWSET(...)

GETDATE() is only one of many options. If your column does not support NULL values, you have to provide another value.

Greets Flo

0

精彩评论

暂无评论...
验证码 换一张
取 消