C# CIMES里面切换数据库(只适用于我们公司的代码)
//当前页面连接的是170数据库,切换到176数据库 CustomDataAgent dataAgent = DBCenter.Create(Utility.AppSetting.WMSConnection); //查询176数据库的MES_AOI_WO表 string sqlAOIWO = @"SELECT WO,BATCHFLAG, BATCHID FROM MES_AOI_WO WHERE WO =#[STRING]"; DataTable dtAOIWO = dataAgent.GetDataTable(SQLCenter.Parse(sqlAOIWO, WO));
//如果要改变数据库字段里的内容,则需要改变using括号里的内容 using (var cts = CimesTransactionScope.Create(Utility.AppSetting.WMSConnection)) { if (dtAOIWO.Rows.Count > 0) { string sqlUpdateAOIWO = "UPDATE MES_AOI_WO SET BATCHFLAG = #[STRING],BATCHID =#[STRING] WHERE WO = #[STRING] "; DBCenter.ExecuteParse(sqlUpdateAOIWO, "X", BatchID, WO); } cts.Complete(); }
//如果using里面的Create括号里没内容,则默认连接当前数据库 using (CimesTransactionScope cts = CimesTransactionScope.Create()) { }