Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am inserting bulk data from excel to sql database. i am using SqlBulkCopy for insertion. but i want to do validation. for example if there s no data in one of the cell of cell means it should check and error message should display. help. am in urgency. i tried using while loop. but not working.
This my code:
C#
while (dReader.Read())
       {
           SqlBulkCopy sb = new SqlBulkCopy(con);


           sb.DestinationTableName = "sampletable";

           sb.ColumnMappings.Add("adate", "adate");
           if (dReader[1].ToString() == "")
           {
               Label1.Text = "check";

           }
           else
           {
               sb.ColumnMappings.Add("ex_id", "ex_id");
           }
           sb.ColumnMappings.Add("empid", "empid");
           sb.ColumnMappings.Add("name", "name");
           sb.ColumnMappings.Add("sal", "sal");

           con.Open();

           sb.WriteToServer(dReader);
       }
Posted
Updated 9-Apr-10 21:23pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900