[此贴子已经被作者于2006-11-14 11:49:04编辑过]
以下是一个定时器过程,我想每次将一个FOXPRO数据库查询到DATASET里,然后再更新一个CONNECTION连接上的ACCESS数据库,库中的表名为CURRDAYBUSINFO
private void Timer_Scan_Tick(object sender, System.EventArgs e)
{
string PubConnstr,Sqlstr;
Timer_Scan.Enabled = false ;//关闭定时器,以免没有执行完再次进入过程
Txt_Info.Text = "进入扫描过程";
Txt_Info.Refresh();
Timer_Scan.Enabled = false;
QueryCount = QueryCount + 1;
OdbcConnection OdbcConn = new OdbcConnection() ;
OdbcDataAdapter OdbcData = new OdbcDataAdapter();
OdbcCommand OdbcComm = new OdbcCommand();
DataSet TmpDs = new DataSet();
Pathstr = Application.StartupPath ;
PubConnstr = "provider=MSDASQL.1;user id=admin;password=;driver=microsoft visual foxpro driver;sourcedb="+Pathstr+";sourcetype=dbf;Persist Security Info=False";
OdbcConn.ConnectionString = PubConnstr;
OdbcConn.Open();
Txt_Info.Text = "打开数据库正常...";
Txt_Info.Refresh();
Sqlstr = "Select * From Piaolst where days > {^2006-10-10}";
OdbcComm.CommandText = Sqlstr;
OdbcComm.Connection = OdbcConn;
OdbcComm.ExecuteNonQuery();
Txt_Info.Text = "查询数据库正常...";
Txt_Info.Refresh();
OdbcData.SelectCommand = OdbcComm;
OdbcData.Fill(TmpDs,"Piaolst");
Txt_Count.Text = TmpDs.Tables[0].Rows.Count.ToString();
Timer_Scan.Enabled = true;
Txt_Info.Text = "查询次数:"+ QueryCount.ToString();
Txt_Info.Refresh();
//-------------------------------------------------------------------------------------------------
OleDbConnection OleConn = new OleDbConnection();
OleDbDataAdapter OleData = new OleDbDataAdapter();
OleDbCommand OleComm = new OleDbCommand();
OleConn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;persist security info=false ;data source="+Application.StartupPath+"\\CurrDayBusinfo.mdb";
OleConn.Open();
OleComm.CommandText = "Select * from CurrDayBusinfo";
OleComm.Connection = OleConn;
OleDbCommandBuilder OleBuilder =new OleDbCommandBuilder(OleData);
//----------------------------------------------------------------------------------------
try
{
lock(this) //处理并发情况(分布式情况)
{
OleData.Update(TmpDs,"CurrDayBusinfo");//想通过这里来将TMPDS的数据更新到currdaybusinfo
}
}
catch(Exception err)
{
OleConn.Close();
//throw new BusinessException(err);
}
//-------------------------------------------------------------------------------------------------
Timer_Scan.Enabled = true ;//再次打开定时器,让程序重新进入这个过程,
panel1.Refresh();
OdbcConn.Close();
}
以上程序无效,不能更新TMPDS里的数据到ACCESS数据库CURRDAYBUFINFO里的表CURRDAYBUSINFO