Ekrem Tapan

Ekrem Tapan

  • NA
  • 967
  • 81.2k

when use SQLBULKCOPY if record exist how can i update ?

Apr 8 2016 2:30 AM
hello everybody, 
 
im using excel table import to sql,
 
if i already have a same record how can i update it then continue import other data ?  
 
DataTable dt = new DataTable();
dt.Columns.Add("SHEET", typeof(int));
dt.Columns.Add("DATE", typeof(DateTime));
dt.Columns.Add("DATA", typeof(string));
dt.Columns.Add("CODE", typeof(string));
IRow excelRow = default(IRow);
excelRow = sheet.GetRow(0);
for (int Cel = 1; Cel <= excelRow.LastCellNum - 1; Cel++)
{
var cellValue = excelRow.GetCell(Cel);
for (int k = 1; k <= sheet.LastRowNum - 1; k++)
{
string code = cellValue.ToString();
var date = sheet.GetRow(k).GetCell(0);
var value = sheet.GetRow(k).GetCell(Cel);
string dates = date.ToString();
string values = value.ToString();
dt.Rows.Add(b, dates, values, code);
}
}
cnn.Open();
SqlBulkCopy bulkCopy = new SqlBulkCopy(cnn);
bulkCopy.DestinationTableName = "RMQ_DATA";
bulkCopy.WriteToServer(dt);
cnn.Close();
 

Answers (1)