我有这样一个方法public DataSet CallProcedure(string szProcedureName, string args)
{
DataSet proDs = new DataSet();
CommClass comm = new CommClass();
SqlConnection conn = comm.myconnection;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(szProcedureName, conn);
conn.Open();
sqlAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
string[] procedureArgs = Regex.Split(args, "-");
string[] proArgs;
foreach (string str in procedureArgs)
{ SqlParameter sqlPar = new SqlParameter(); proArgs = Regex.Split(str, ",");
for (int i = 0; i < 1; i++)
{
sqlPar.ParameterName = "" + proArgs[0].ToString() + "";
sqlPar.SqlDbType = SqlDbType.Int;
sqlPar.Value = Convert.ToInt32(proArgs[3]);
if (proArgs[2] == "1")
{
sqlPar.Direction = ParameterDirection.Input;
}
else if (proArgs[2] == "2")
{
sqlPar.Direction = ParameterDirection.Output;
}
sqlPar.Value = proArgs[4]; } sqlAdapter.SelectCommand.Parameters.Add(sqlPar);
sqlAdapter.Fill(proDs);
}
conn.Close(); if (proDs != null)
{
return proDs;
}
else
{
return null;
}
调用是这样的
string ss = "@id,,1,4,3-@name,,1,4,2";
this.rpt.DataSource=CallProcedure("pr1", ss);
this.rpt.DataBind();现在有个问题。
程序说为存储过程提供的参数太多。
请问我要如何修改才能正确执行我这个传进入的 ss
{
DataSet proDs = new DataSet();
CommClass comm = new CommClass();
SqlConnection conn = comm.myconnection;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(szProcedureName, conn);
conn.Open();
sqlAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
string[] procedureArgs = Regex.Split(args, "-");
string[] proArgs;
foreach (string str in procedureArgs)
{ SqlParameter sqlPar = new SqlParameter(); proArgs = Regex.Split(str, ",");
for (int i = 0; i < 1; i++)
{
sqlPar.ParameterName = "" + proArgs[0].ToString() + "";
sqlPar.SqlDbType = SqlDbType.Int;
sqlPar.Value = Convert.ToInt32(proArgs[3]);
if (proArgs[2] == "1")
{
sqlPar.Direction = ParameterDirection.Input;
}
else if (proArgs[2] == "2")
{
sqlPar.Direction = ParameterDirection.Output;
}
sqlPar.Value = proArgs[4]; } sqlAdapter.SelectCommand.Parameters.Add(sqlPar);
sqlAdapter.Fill(proDs);
}
conn.Close(); if (proDs != null)
{
return proDs;
}
else
{
return null;
}
调用是这样的
string ss = "@id,,1,4,3-@name,,1,4,2";
this.rpt.DataSource=CallProcedure("pr1", ss);
this.rpt.DataBind();现在有个问题。
程序说为存储过程提供的参数太多。
请问我要如何修改才能正确执行我这个传进入的 ss
解决方案 »
- 如何在当前结果中进行查找
- 正则提取img标签属性与值(C#)
- 在以下方法或属性之间的调用不明确:“Microsoft.Reporting.WebForms.ReportDataSource.ReportData
- gridview 类似树形结构的展开收缩功能
- 邮件系统的问题——————>>请问怎么用pop3收邮件?
- Title的样式问题?
- 请问怎么处理二进制数据
- 送给ln老大的分
- 为什么JS给DropDownList添加下拉选项后台取不到 而JS给隐藏域赋值后台却取的到?
- 请问有什么好的,用C#开发的免费公开全部源代码的论坛?
- 下面的var sld3 = new Slider("idSlider3", "idBar3", 声明后没有使用啊 ,那有如何绑定的呢?
- 怎样写文件
2.那就直接用一個參數ss帶進去.然後在sql中用去分解這些參數。
我传入的这个参数是这样的
string ss = "@id,,1,4,3-@name,,1,4,2";
然后在方法中用split先按“-”分割成两个:"@id,,1,4,3和@name,,1,4,2
然后在执行的。
现在报我上面的错
我在方法中这个部分已经加上“”了。不需要加‘’加了更报错
sqlPar.ParameterName = "" + proArgs[0].ToString() + "";
For(int i=0;i<??;i++)这边你自己看着改下
多了一个,
调试看看sqlPar值
if(!string.IsNullOrEmpty(proArgs[0].ToString())
{
sqlPar.ParameterName = "" + proArgs[0].ToString() + "";
sqlPar.SqlDbType = SqlDbType.Int;
sqlPar.Value = Convert.ToInt32(proArgs[2]);
if (proArgs[1] == "1")
{
sqlPar.Direction = ParameterDirection.Input;
}
else if (proArgs[1] == "2")
{
sqlPar.Direction = ParameterDirection.Output;
}
}
for (int i = 0; i < 1; i++)
{
sqlPar.ParameterName = "" + proArgs[0].ToString() + "";
sqlPar.SqlDbType = SqlDbType.Int;
sqlPar.Value = Convert.ToInt32(proArgs[3]);
if (proArgs[2] == "1")
{
sqlPar.Direction = ParameterDirection.Input;
}
else if (proArgs[2] == "2")
{
sqlPar.Direction = ParameterDirection.Output;
}
sqlPar.Value = proArgs[4]; } sqlAdapter.SelectCommand.Parameters.Add(sqlPar);=====================================
看起来只new了一个,没有问题吗?我没试过
你看看最后执行前,Parameters有几个
for (int i = 0; i < 1; i++)
{
sqlPar.ParameterName = "" + proArgs[0].ToString() + "";
sqlPar.SqlDbType = SqlDbType.Int;
sqlPar.Value = Convert.ToInt32(proArgs[3]);
if (proArgs[2] == "1")
{
sqlPar.Direction = ParameterDirection.Input;
}
else if (proArgs[2] == "2")
{
sqlPar.Direction = ParameterDirection.Output;
}
sqlPar.Value = proArgs[4]; } sqlAdapter.SelectCommand.Parameters.Add(sqlPar);
SqlParameter sqlPar = new SqlParameter();
sqlAdapter.SelectCommand.Parameters.Add(sqlPar);
这两行应该在for循环里面的吧