请问这里参数'@ID'为什么没有提供?我检查了好半天也没发现问题。
System.Data.SqlClient.SqlException: 过程 'SelReMsgByParm' 需要参数 '@id',但未提供该参数。public void BindData()
    {
        string tid = Request.QueryString["NewsID"];
        //Response.Write(tid);
       // Response.End();
        SqlParameter[] myparm = new SqlParameter[1];
        myparm[0] = new SqlParameter("@id", SqlDbType.Int, 4);
        myparm[0].Value = tid;       // myparm.ParameterName = "id";
       // myparm.SqlDbType = SqlDbType.Int;
       // myparm.Value = tid;
       
        string resqlexec = "SelReMsgByParm";
        SqlCommand cmd = new SqlCommand();
        using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
        {
            conn.Open();
            SqlDataReader mydr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, resqlexec,myparm);
            if (mydr.Read())
            {
                SqlDataAdapter adapter = new SqlDataAdapter(resqlexec, conn);
                DataSet rs = new DataSet();
                adapter.Fill(rs);
                DataList1.DataSource = rs.Tables["BxxsRemsg"];
                DataList1.DataBind();
            }
            conn.Close();        }存储过程:CREATE PROCEDURE SelReMsgByParm
@id int 
AS 
Select * from [BxxsRemsg] where LogID = @id
GO

解决方案 »

  1.   

    你试一下这个方法:你把你的SqlParameter对象添加到SqlCommand.Parameters.Add("SqlParameter") 方法里
      

  2.   

    @id 的值好像是String型??
      

  3.   

    类型不一致吧
    tid和 @id
      

  4.   

    不是类型的问题啊,我把tid改写成int tid =Convert.ToInt32(Request.QueryString["NewsID"]);
    这样也不行啊,还是同样的问题
      

  5.   


    没有见到
    command.Parameters.Add
      

  6.   

    SqlDataAdapter adapter = new SqlDataAdapter(resqlexec, conn); 
    尤其是这里
      

  7.   

    天啊,看不懂楼主的代码,命令对象的参数集合里没有添加这个参数,而且CMD这个命令对象我都没看到在哪用Y???
    建议楼主仔细检查代码吧,咋这样子的啊?一般的,你可以搞配置好CONN后,再搞定CMD和CMD的CONNTIONE属性参数的话,可用用CMD的Create()方法到生成,然后搞定参数的各属性后,得添加到CMD参数集合中
     //生成命令对象
            DbCommand comm = GenericDataAccess.CreateCommand();//这里已配置好命令对象的属性了,是自己封装的一个函数
            //设置命令对象要执行的存储过程名称
            comm.CommandText = "ShoppingCartUpdateItem";
            //生成参数
            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@CartID";
            param.Value = shoppingCartId;
            param.DbType = DbType.String;
            param.Size = 36;
            comm.Parameters.Add(param);
      

  8.   

      SqlParameter[] myparm = {new SqlParameter("@id", SqlDbType.Int, 4);}; 
      myparm[0].Value = tid; 用了SqlHelper.cs为什么不直接用SqlHelper.ExecuteDataset 来返回一个DataSet呢?
    把你的代码直接改成下面的:Dataset ds= SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "SelReMsgByParm" ,myparm); //返回一个DataSetDataList1.DataSource = ds.Tables[0]; 
    DataList1.DataBind();  
      

  9.   

    我不知道你的SqlHelper有没有ExecuteDataset,如果直接从petshop中拷的就没有,那你自己可以microsoft的网站下载, use google to search the keyword for "DAAB" (Data Access Application Block)
      

  10.   

    myparm[0].Value = tid; 
    tid要转成int型