想每隔1秒向数据库中写入当前时间,结果没过几秒,数据库中有了几千条时间,顺序也不对,不知为什么? private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer1.Enabled = true;
} private void timer1_Tick(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(con);
SqlCommand com = new SqlCommand("select * from test0419", cn);
SqlDataAdapter adp = new SqlDataAdapter(com); DataSet ds = new DataSet();
adp.Fill(ds, "test0419"); DataTable dt = ds.Tables[0];
DataRow newRow;
newRow = dt.NewRow();
newRow["时间"] = System.DateTime.Now.ToString();
dt.Rows.Add(newRow);
SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(con, SqlBulkCopyOptions.UseInternalTransaction);
sqlbulkcopy.DestinationTableName = "test0419";
sqlbulkcopy.WriteToServer(dt);
}
SQLC#datatime
{
timer1.Interval = 1000;
timer1.Enabled = true;
} private void timer1_Tick(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(con);
SqlCommand com = new SqlCommand("select * from test0419", cn);
SqlDataAdapter adp = new SqlDataAdapter(com); DataSet ds = new DataSet();
adp.Fill(ds, "test0419"); DataTable dt = ds.Tables[0];
DataRow newRow;
newRow = dt.NewRow();
newRow["时间"] = System.DateTime.Now.ToString();
dt.Rows.Add(newRow);
SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(con, SqlBulkCopyOptions.UseInternalTransaction);
sqlbulkcopy.DestinationTableName = "test0419";
sqlbulkcopy.WriteToServer(dt);
}
SQLC#datatime
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货