I have one problem. when i importing csv file into sql server 2005, its imported data properly but one row less of the total record. Below is my Code.
SqlConnection con = new SqlConnection(@"Data Source=server-1;Initial Catalog=CAF_Retrieval;user id=sa; password=sa;");
string filepath = textInput.Text;
StreamReader sr = new StreamReader(filepath);
string line = sr.ReadLine();
string[] value = line.Split(',');
DataTable dt = new DataTable();
DataRow row;
foreach (string dc in value)
{
dt.Columns.Add(new DataColumn(dc));
}
while (!sr.EndOfStream)
{
value = sr.ReadLine().Split(',');
if (value.Length == dt.Columns.Count)
{
row = dt.NewRow();
row.ItemArray = value;
dt.Rows.Add(row);
}
}
SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock);
bc.DestinationTableName = "Upload_Data";
bc.BatchSize = dt.Rows.Count;
con.Open();
bc.WriteToServer(dt);
bc.Close();
con.Close();
Also i want remove the duplicates records when i m importing the next csv. or i want to collect that duplicates at one folder. Also i want to show the progressbar while loading the data and its time, percentage and message to data imported successfully.
Can anybody give me the idea or code to implement this?

New Topic/Question
Reply




MultiQuote



|