在项目的开发中使用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