tags:

views:

33

answers:

2

Cannot insert 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....

A: 

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

Florian Reischl
Not yet. I have 4 varchars columns and 3 date columns. on sheet 1.
Crimsonland
A: 

Also refer this http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan
Yeah i just follow the same procedure there but if always have successful upload and if i delete the records and create a new one again that error always show..
Crimsonland