1

I'm trying to import data from an Excel sheet into a sqlserver database. I used the sample code that is in this link. However, when an import is made extra 22 rows with NULL values are being copied. I'm not sure how to remove the NULL values.

Database screen shot

1
  • Still not sure why the NULL values are being copied and exactly 22 rows each time. Commented Apr 23, 2014 at 15:12

2 Answers 2

3

In the select statement, try adding a WHERE clause to exclude the nulls. EX.

select student,rollno,course from [sheet1$]

Becomes:

select student,rollno,course from [sheet1$] where student IS NOT NULL
Sign up to request clarification or add additional context in comments.

Comments

0

In the code

    while (dr.read())
    {
        bulkcopy.writetoserver(dr);
    }

you could check dr to see whether all of the columns are null, and if so skip the call to bulkcopy.writetoserver().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.