插件开发之DB操作--select示例原创
金蝶云社区-闪闪我最靓
闪闪我最靓
13人赞赏了该文章 1,682次浏览 未经作者许可,禁止转载编辑于2019年11月25日 17:20:10

引用:using Kingdee.BOS.ServiceHelper;

示例:

private void GetInfoComId(string fid, out string formId, out string paramFormId, out string name)
        {

            /*1. Select语句*/
            string strSQL = string.Format("select t0.finfocomparamid,t0.finfocomid ,t1.fname\r\nfrom t_bas_infocomreg t0 left Join t_bas_infocomreg_l t1 on t0.fid=t1.fid and t1.flocaleid=2052\r\nwhere fnumber='{0}'", fid);

           

             /* 2.DB 操作 :DBServiceHelper.ExecuteDataSet 详情请看下面*/
            DataSet dataSet = DBServiceHelper.ExecuteDataSet(base.Context, strSQL);
           

             /*3.对查询结果进行校验*/           

             if (dataSet != null && dataSet.Tables.Count > 0)
            {

                /*4.注意类型转换*/
                formId = (dataSet.Tables[0].Rows[0]["finfocomid"] as string);
                paramFormId = (dataSet.Tables[0].Rows[0]["finfocomparamid"] as string);
                name = (dataSet.Tables[0].Rows[0]["fname"] as string);
                return;
            }
            string text;
            name = (text = "");
            string text2;
            paramFormId = (text2 = text);
            formId = text2;
        }



-----------------------------------------------------------------------------------------------

以下是DBServiceHelper.ExecuteDataSet方法的实现,我们不用过分关心此方法如何实现,直接引用【Kingdee.BOS.ServiceHelper.DBServiceHelper】使用即可。


// Kingdee.BOS.ServiceHelper.DBServiceHelper
public static DataSet ExecuteDataSet(Context ctx, string strSQL)
{
    IDBService dBService = ServiceFactory.GetDBService(ctx);
    DataSet result;
    try
    {
        DataSet dataSet = dBService.ExecuteDataSet(ctx, strSQL);
        ServiceFactory.CloseService(dBService);
        result = dataSet;
    }
    finally
    {
        ServiceFactory.CloseService(dBService);
    }
    return result;
}

图标赞 13
13人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!