只要我有一個Excel文件,我裝成SQL Server 2008中如何自動插入當前日期,同時將數據插入到SQL Server 2008
我想插入當前日期爲從Excel而添加日期相同的細胞轉移...然後每次添加數據時自動插入日期,永不丟失舊日期。我怎樣才能做到這一點?
string ssqltable = comboBox1.GetItemText(comboBox1.SelectedItem);
string myexceldataquery = "select * from [" + ssqltable + "$]";
try
{
OleDbConnection oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + imagepath + ";Extended Properties='Excel 12.0 Xml; HDR=YES;IMEX=1;';");
string ssqlconnectionstring = "Data Source=.;Initial Catalog=Bioxcell;Integrated Security=true";
OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oconn);
oconn.Open();
SqlBulkCopy bulkcopy = new SqlBulkCopy(ssqlconnectionstring);
DataTable dt = new DataTable();
dt.Load(oledbcmd.ExecuteReader());
bulkcopy.DestinationTableName = ssqltable;
for (int i = 0; i < dt.Columns.Count; i++)
{
bulkcopy.ColumnMappings.Add(i, i);
}
bulkcopy.WriteToServer(dt);
oconn.Close();
}
我用這個,但我知道插入只有最後一個記錄 我想在新創建的行插入當前日期和不輸以前的專欄日期。例如,當我每次插入數據插入新的日期節能與舊日期
SqlCommand Update6 = new SqlCommand("insert into Overseas (Date) Values('" + DateTime.Now.ToShortDateString() + "')", conn);
Update6.ExecuteScalar();
舊數據,而使用
SqlCommand Update6 = new SqlCommand("insert into Overseas (Date) Values (GETDATE())", conn);
Update6.ExecuteNonQuery();
結果被
enter image description here 那麼解決方案是什麼?
提示:列定義中的'DEFAULT getdate()'。 –
抱歉不明白..你能解釋一下嗎? –
post edited ....../ –