您的位置:首页 > 理论基础 > 计算机网络

从"常规网络错误。请检查您的网络文档"想起推销我封装的存储过程调用

2005-12-31 11:46 447 查看
看到 蝈蝈俊.Net 的一篇blog : http://blog.joycode.com/ghj/archive/2005/12/29/69703.aspx 是对"常规网络错误。请检查您的网络文档"的异常分析,其实我也遇到过这个问题.也是在给存储过程加parameter的时候类型(或大小)不合要求.后来我改进了自己封装的存储过程调用类,关键是我从存储过程中找出他需要的参数类型,再把参数一个一个按他需要的样子塞进去.这个问题就迎刃而解,不劳操心了.我觉得我的实现还是不错的呵呵.

代码有点长,关键的两句是:
SqlCommandBuilder.DeriveParameters(sqlCmd);

for(int i=0;i<sqlParam.Count;i++)
{
sqlCmd.Parameters.Add(new SqlParameter(sqlParam[i].ParameterName, sqlParam[i].SqlDbType,sqlParam[i].Size,
sqlParam[i].Direction, sqlParam[i].IsNullable, sqlParam[i].Precision, sqlParam[i].Scale,
sqlParam[i].SourceColumn, sqlParam[i].SourceVersion, parameterValues.GetValue(i)));
}

代码:

using System;
2using System.Data;
3using System.Data.SqlClient;
4using System.Diagnostics;
5using System.Collections;
6using System.Xml;
7
8namespace crawl
9
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: