如何解决Remoting无法传输存储过程参数的问题
2008-04-24 04:00
711 查看
在项目的开发中使用Remoting,并且所有的数据请求服务都是通过Remoting完成的,所以自然就在其中到了传递参数的存储过程,在业务逻辑中把参数构建好后传递到Remoting服务端,在取出存储过程的参数时报错,具体错误不记得了,自己尝试了各种方法也不行,上网资讯也没有结果,最后变通了一下,问题解决了,例子如下:以下部分为客户调用端
1//先声明参数
2 private const string PARAM_GUID = "@GUID";
3 private const string PARAM_VGA_TREEGUID = "@VGATreeGUID";
4 private const string PARAM_MB_TREEGUID = "@MBTreeGUID";
5
6 public static string GetProductTypeByGUID(string GUID, String VGATreeID, String MbTreeID)
7 {
8 try
9 {
10 int lcID = Thread.CurrentThread.CurrentUICulture.LCID;
11
12 BaseModel bt = new BaseModel();
13
14 //构建一个哈希表,把参数依次压入
15 Hashtable parames = new Hashtable();
16 parames.Add(PARAM_PROGUID, GUID);
17 parames.Add(PARAM_VGA_TREEGUID, VGATreeID);
18 parames.Add(PARAM_MB_TREEGUID, MbTreeID);
19
20 //把存储过程名称和带参数的哈希表传入
21 DataAccess.DataBase.RunProcedureDataSet(lcID, "GetProductTypeByTreeID", parames, ref bt);
22
23 return bt.Rows[0]["ProductType"].ToString();
24 }
25 catch (Exception ex)
26 {
27 CommFunction.WriteErrorLogFile("public static string GetProductTypeByGUID(stirng GUID, String VGATreeID, String MbTreeID)出错:" ex.Message);
28 return "Other";
29 }
30 }
31
32
以下为服务端:
1public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)#region public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)
2 // -----------------------------------------------------------------------------------------
3 public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)
4 {
5 if (!CheckRemotingClient())
6 {
7 return;
8 }
9 Console.WriteLine(DateTime.Now.ToString() "调用了Query(" lcid.ToString() ", string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)");
10 int i = cmdHashtable.Count;
11 //以下构造存储过程参数
12 SqlParameter[] cmdParms = new SqlParameter[i];
13 int j = 0;
14 foreach (DictionaryEntry de in cmdHashtable)
15 {
16 cmdParms[j] = new SqlParameter(de.Key.ToString(), de.Value);
17 j ;
18 }
19 Colorful.DBUtility.DbHelperSQL.Query(lcid, SQLString, cmdParms, ref baseModel);
20 }
21 // -----------------------------------------------------------------------------------------
22 #endregion http://www.cnblogs.com/blockhead/archive/2006/08/17/479720.html
1//先声明参数
2 private const string PARAM_GUID = "@GUID";
3 private const string PARAM_VGA_TREEGUID = "@VGATreeGUID";
4 private const string PARAM_MB_TREEGUID = "@MBTreeGUID";
5
6 public static string GetProductTypeByGUID(string GUID, String VGATreeID, String MbTreeID)
7 {
8 try
9 {
10 int lcID = Thread.CurrentThread.CurrentUICulture.LCID;
11
12 BaseModel bt = new BaseModel();
13
14 //构建一个哈希表,把参数依次压入
15 Hashtable parames = new Hashtable();
16 parames.Add(PARAM_PROGUID, GUID);
17 parames.Add(PARAM_VGA_TREEGUID, VGATreeID);
18 parames.Add(PARAM_MB_TREEGUID, MbTreeID);
19
20 //把存储过程名称和带参数的哈希表传入
21 DataAccess.DataBase.RunProcedureDataSet(lcID, "GetProductTypeByTreeID", parames, ref bt);
22
23 return bt.Rows[0]["ProductType"].ToString();
24 }
25 catch (Exception ex)
26 {
27 CommFunction.WriteErrorLogFile("public static string GetProductTypeByGUID(stirng GUID, String VGATreeID, String MbTreeID)出错:" ex.Message);
28 return "Other";
29 }
30 }
31
32
以下为服务端:
1public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)#region public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)
2 // -----------------------------------------------------------------------------------------
3 public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)
4 {
5 if (!CheckRemotingClient())
6 {
7 return;
8 }
9 Console.WriteLine(DateTime.Now.ToString() "调用了Query(" lcid.ToString() ", string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)");
10 int i = cmdHashtable.Count;
11 //以下构造存储过程参数
12 SqlParameter[] cmdParms = new SqlParameter[i];
13 int j = 0;
14 foreach (DictionaryEntry de in cmdHashtable)
15 {
16 cmdParms[j] = new SqlParameter(de.Key.ToString(), de.Value);
17 j ;
18 }
19 Colorful.DBUtility.DbHelperSQL.Query(lcid, SQLString, cmdParms, ref baseModel);
20 }
21 // -----------------------------------------------------------------------------------------
22 #endregion http://www.cnblogs.com/blockhead/archive/2006/08/17/479720.html
相关文章推荐
- 如何解决Remoting无法传输存储过程参数的问题
- 如何解决Remoting无法传输存储过程参数的问题
- 使用复制存储过程执行解决“事务复制中的表大量更新导致无法及时同步”的问题
- 解决SQL中in参数在存储过程中的传递问题
- 使用复制存储过程执行解决“事务复制中的表大量更新导致无法及时同步”的问题
- 解决SQL中in参数在存储过程中的传递有关问题
- 如何解决VS2010 Premium RC 版安装过程中,无法输入key的问题
- PL/SQL Developer中,存储过程无法调试的问题解决办法
- html 之间如何通过URL传输参数,并解决中文乱码问题
- SQL server 存储过程中解决整数参数的传递问题
- 使用复制存储过程执行解决“事务复制中的表大量更新导致无法及时同步”的问题 (转)
- 终于解决了--调用存储过程提示传递参数多的问题!
- PL/SQL Developer中,存储过程无法调试的问题解决办法
- 如何解决JavaScript中UUID作为方法参数在方法中无法传递而数字却正常传递的问题
- 解决sybase存储过程中不能取得动态sql输出参数的问题
- MySql存储过程中limit不能动态参数问题的解决
- PL/SQL Developer中,存储过程无法调试的问题解决办法
- 存储过程使用逗号分隔作为IN参数疑难问题解决方法【真正解决】
- 利用反射传输存储过程参数,在mssql和mysql两种数据库中存在的问题
- 如何解决mid使用过程中出现的以下问题(无效的过程调用或参数: 'mid')