1.服务端数据访问服务DataAccessService
//常用接口方法
string GetSqlOfNextSeqValue(string p_seqName);
int ExecuteNonQuery(string p_commandText);
string ExecuteScalar(string p_commandText);
DataSet GetDataSet(string p_commandText);
int ExecuteStoredProcedure(string p_storedProcedureName);
//获取一组数据
Hashtable readValues = new Hashtable();
string objID, mc;
string sql = string.Format("SELECT OBJ_ID, MC FROM MW_SYS.MWT_UD_HT WHERE HTID = '{0}'", xhID);
DataSet ds = DataAccessService.GetDataSet(sql);
for (int i=0; i<ds.Tables[0].Rows.Count; i++)
{
objID = (string)ds.Tables[0].Rows[i]["OBJ_ID"];
mc = (string)ds.Tables[0].Rows[i]["MC"];
readValues.Add(objID, mc);
}
Hashtable readValues = new Hashtable();
string objID, mc;
string sql = string.Format("SELECT OBJ_ID, MC FROM MW_SYS.MWT_UD_HT WHERE HTID = '{0}'", xhID);
DataSet ds = DataAccessService.GetDataSet(sql);
for (int i=0; i<ds.Tables[0].Rows.Count; i++)
{
objID = (string)ds.Tables[0].Rows[i]["OBJ_ID"];
mc = (string)ds.Tables[0].Rows[i]["MC"];
readValues.Add(objID, mc);
}
//获取数据,并将查询返回结果集中第一行第一列值以字符串形式返回
string sql = string.Format("SELECT MC FROM MW_SYS.MWT_UD_HT WHERE OBJ_ID = '{0}'", BD.ID);
string mc = (string)DataAccessService.ExecuteScalar(sql);
string sql = string.Format("SELECT MC FROM MW_SYS.MWT_UD_HT WHERE OBJ_ID = '{0}'", BD.ID);
string mc = (string)DataAccessService.ExecuteScalar(sql);
//更新数据
string sql = "UPDATE MW_SYS.MWT_UD_HT SET SX1 = '{0}', SX2 = '{1}' WHERE OBJ_ID = '{2}'";
sql = string.Format(sql, new object[3] { sx1, sx2, BD.ID });
DataAccessService.ExecuteNonQuery(sql);
string sql = "UPDATE MW_SYS.MWT_UD_HT SET SX1 = '{0}', SX2 = '{1}' WHERE OBJ_ID = '{2}'";
sql = string.Format(sql, new object[3] { sx1, sx2, BD.ID });
DataAccessService.ExecuteNonQuery(sql);
2.客户端数据访问服务RemoteDataAccessService
与DataAccessService类似
3.关于Web二次开发,在客户端获取数据方法
需要在页面引用数据访问代理组件,引用代码方式如下:<mw:DataAccessAgent ID="popWinDataAccessAgent" runat="server" />
该代理对象有以下方法
mw.data.DataAccessAgentClass.executeNonQuery(p_sql) 方法
mw.data.DataAccessAgentClass.executeQuery(p_sql) 方法
mw.data.DataAccessAgentClass.getConnectionString() 方法
var name = mw.Portal.currentUser.name;
var sql = "select FJR,BT,SJR,NR,FSSJ,SFYD,OBJ_ID from mw_app.PM_NW_ZH_XMS_SJ where SJR='"+name+"' order by FSSJ desc";
var pop3Table = mw.data.DataAccessAgent.executeQuery(sql);
//将数据填充arr
arr = new Array();
for(var i=0;i<pop3Table.rows.length;i++)
{
arr[arr.length]=pop3Table.rows[i].getValues();
}
var sql = "select FJR,BT,SJR,NR,FSSJ,SFYD,OBJ_ID from mw_app.PM_NW_ZH_XMS_SJ where SJR='"+name+"' order by FSSJ desc";
var pop3Table = mw.data.DataAccessAgent.executeQuery(sql);
//将数据填充arr
arr = new Array();
for(var i=0;i<pop3Table.rows.length;i++)
{
arr[arr.length]=pop3Table.rows[i].getValues();
}
4.关于Web二次开发,在服务器端获取数据方法,注意这时候需要改变继承对象为NariIS.PI3000.Portal.Framework.WebView
private NariIS.PI3000.Service.Base.RemoteDataAccessService _remoteDataAccessService;
/// <summary>
/// 数据库访问服务对象
/// </summary>
public NariIS.PI3000.Service.Base.RemoteDataAccessService RemoteDataAccessService
{
get
{
if (_remoteDataAccessService == null)
{
_remoteDataAccessService = new NariIS.PI3000.Service.Base.RemoteDataAccessService();
}
return _remoteDataAccessService;
}
}
private void GetDataFromDB(string p_sql)
{
DataSet ds = RemoteDataAccessService.GetDataSet(p_sql);
return ds;
}
/// <summary>
/// 数据库访问服务对象
/// </summary>
public NariIS.PI3000.Service.Base.RemoteDataAccessService RemoteDataAccessService
{
get
{
if (_remoteDataAccessService == null)
{
_remoteDataAccessService = new NariIS.PI3000.Service.Base.RemoteDataAccessService();
}
return _remoteDataAccessService;
}
}
private void GetDataFromDB(string p_sql)
{
DataSet ds = RemoteDataAccessService.GetDataSet(p_sql);
return ds;
}