如今,我都试图从我的数据网格中获取数据,并插入我的服务器,但我却在插入部分,这是我迄今为止所做的。
private void button1_Click(object sender, EventArgs e)
{
var fdlg = new OpenFileDialog();
fdlg.Title = @"Site Assist Database Update";
fdlg.InitialDirectory = @"c:";
fdlg.Filter = @"CSV Files (*.csv)|*.csv";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
string filepath = fdlg.FileName;
var engine = new FileHelperEngine<PartList>();
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
PartList[] res = engine.ReadFile(filepath);
if (engine.ErrorManager.ErrorCount > 0)
engine.ErrorManager.SaveErrors("Errors.txt");
var table = new DataTable();
table.Columns.Add("Part Number", typeof (string));
table.Columns.Add("Part Name", typeof(string));
table.Columns.Add("On Hand New", typeof(string));
table.Columns.Add("On Hand Fixed", typeof(string));
table.Columns.Add("SC5 - Storage Bin - EAME", typeof(string));
table.Columns.Add("Is ASL Item", typeof(string));
table.Columns.Add("Reorder Point", typeof(string));
table.Columns.Add("Stock Maximum", typeof(string));
table.Columns.Add("On Order", typeof(string));
table.Columns.Add("Back Order", typeof(string));
table.Columns.Add("Part Cost", typeof(string));
table.Columns.Add("PC11 - Repairable - EAME", typeof(string));
foreach (PartList row in res)
{
table.Rows.Add(row.PartNum, row.PartName, row.New, row.Fix, row.Location, row.ASL, row.ReorderPoint,
row.stockMax, row.OnOrder, row.BackOrder, CleanInput(row.Cost), row.Repairable);
}
dataGridView1.DataSource = table;
MessageBox.Show(table.Rows.Count.ToString());
}
}
我对如何做到这一点,已经发现任何真正好的样本。
SqlBulkCopy
is a option but again I will hold my hands up and say I don t know how to do this