开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜