SQLServer -------- 跨库修改(程序和sql 语句两种方式)

1、直接在数据库中使用sql 语句

使用SQLServer 数据库时候注意  库名.dbo.表名.列名

/*
     库A.dbo.表名.字段名
*/
update qd_feixikesaijianguo_Mis4.dbo.tbWaiXie_BomList_PeiLiao set qd_feixikesaijianguo_Mis4.dbo.tbWaiXie_BomList_PeiLiao.CreateTime
 = (SELECT  qd_feixikesaijianguo_Log4.dbo.tbFourLogSystem.CreateTime
FROM   qd_feixikesaijianguo_Log4.dbo.tbFourLogSystem
where qd_feixikesaijianguo_Log4.dbo.tbFourLogSystem.OperatorType ='insert' and 
     qd_feixikesaijianguo_Log4.dbo.tbFourLogSystem.KeyFiles = qd_feixikesaijianguo_Mis4.dbo.tbWaiXie_BomList_PeiLiao.WxPeiLiaoGuid)
where qd_feixikesaijianguo_Mis4.dbo.tbWaiXie_BomList_PeiLiao.QiyeGuid = '1c44eaa1-a12c-4050-8629-6b6d0fc5d0ec'

 

2、借助程序

写一个修改程序,本文是 C#

 

 在界面上使用

 

 主要代码:

<form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Button ID="btnchange" runat="server" Text="change date" OnClick="btnchange_Click" />
         <asp:Label ID="LabelLoadMsg" runat="server" Text="" ForeColor="Red"></asp:Label>
</hr>    </ContentTemplate></asp:UpdatePanel>
    </div>
    </form>



   protected void btnchange_Click(object sender, EventArgs e)
    {
        //找到需要修改的 对象
        List<ITEM.Model.qdMis4.WaiXie_BomList_PeiLiao> mList = _bllPeiLiao.GetListSelWaiXie_BomList_PeiLiao3("*", base.EnterpriseGuid, "");
        for(int i=0;i<=mList.Count -1;i++)
        {
            
            ITEM.Model.qdMis4.WaiXie_BomList_PeiLiao mPeiLiao = mList[i];
            //在另一库的表中 根据关键字进行查找 
            List<ITEM.Model.qdLog4.FourLogSystem> mLogList = _bllLog.GetListSelFourLogSystem3("*", base.EnterpriseGuid, " and KeyFiles='" + mPeiLiao.WxPeiLiaoGuid + "' and OperatorType = 'insert' and LogSqlText like 'insert into tbWaiXie_BomList_PeiLiao%'");
            if(mLogList .Count >0)
            {
                //有的话赋值
                string strsql = "update tbWaiXie_BomList_PeiLiao set CreateTime='" + mLogList[0].CreateTime + "' , UpdateTime='" + mLogList[0].CreateTime + "' where WxPeiLiaoGuid='" + mPeiLiao.WxPeiLiaoGuid + "' and QiyeGuid ='"+base.EnterpriseGuid+"'";
                int k = _bllPeiLiao.SetExByTx(strsql, mPeiLiao.UpdateUserGuid, mPeiLiao.UpdateUserID, mPeiLiao.Update_IP);
            }
        }
        this.LabelLoadMsg.Text = "执行成功+'"+mList.Count+"'";
    }

 

posted on 2020-09-01 17:34  obge  阅读(1359)  评论(0编辑  收藏  举报