存储过程问题,急,在线等待!!!

feeling_vb 2004-05-09 11:24:41

try
{

//查询指标语句
strSqlIndex = " select * from ana_index"+ProPublic.objUserID+" where ana_index_sel ='1' order by ana_index_code ";

//打开连接
SqlConnection conn = ( SqlConnection ) idbmanage.OpenConnection ( true );

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

SqlDataAdapter dataIndex = new SqlDataAdapter( strSqlIndex,conn );
dataIndex.TableMappings.Add ( "Table","Index" );
DataSet ds = new DataSet();
dataIndex.Fill ( ds );

for( int isel =0;isel< ds.Tables["Index"].Rows.Count; isel++ )
{

cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText=ds.Tables["Index"].Rows[isel]["ana_index_proc"].ToString();
cmd.Parameters.Add ( "@strUserId",strUserid );

SqlParameter perResult = cmd.Parameters.Add("@strResult",SqlDbType.Int );
perResult.Direction =ParameterDirection.Output;
cmd.ExecuteNonQuery();

}

}
catch( Exception ex )
{
Console.WriteLine ( ex.Message );
MessageBox.Show ( ex.Message );
}
finally
{
idbmanage.CloseConnection();
}



//------------------- 错误如下:
当纪录 ds.Tables["Index"].Rows.Count =1 的 时候,存储过程可以执行
,当 ds.Tables["Index"].Rows.Count 〉1 的时候存储过程就报错,错误为:
为过程或函数指定的参数太多·!!!
...全文
38 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
feeling_vb 2004-05-09
  • 打赏
  • 举报
回复
谢谢,搞定!!!!
Code4Quality 2004-05-09
  • 打赏
  • 举报
回复
ds.Tables["Index"].Rows.Count 〉1 的时候,你的cmd.Parameters里面已经有了名称为@strUserId的参数了。在for循环cmd.Parameters.Add ( "@strUserId",strUserid );语句之前清除一下cmd.Parameters。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧