本帖最后由 robake 于 2011-02-27 14:13:29 编辑

解决方案 »

  1.   

    SqlConnection sqlconn = new SqlConnection(conn);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = sqlconn;
            cmd.CommandText = "";
            cmd.CommandType = CommandType.StoredProcedure;
            // 创建参数
            IDataParameter[] parameters = {
                    new SqlParameter("@Id", SqlDbType.Int,4) ,
                    new SqlParameter("@Name", SqlDbType.NVarChar,15) ,
                    new SqlParameter("@r", SqlDbType.Int,4)                   // 返回值
                };
            // 设置参数类型
            parameters[0].Direction = ParameterDirection.Output;        // 设置为输出参数
            parameters[1].Value = "";                   // 给输入参数赋值
            parameters[2].Direction = ParameterDirection.ReturnValue;   // 设置为返回值
            // 添加参数
            cmd.Parameters.Add(parameters[0]);
            cmd.Parameters.Add(parameters[1]);
            cmd.Parameters.Add(parameters[2]);        SqlDataAdapter dp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            // 填充dataset
            dp.Fill(ds);
    Convert.ToInt32( ds.Tables[0].Rows[i][""].ToString());
      

  2.   

    依旧是报错,我想取出表里头的html字段的值,用的ds.Tables[0].Rows[i]["html"].ToString(),依旧是报上述的错误
      

  3.   

    改了一下,依旧是报最匹配的重载方法具有一些无效参数,而报错的部分始终是ds.Tables[0].Rows[i],这是为何?        public string getTopMusic()
            {
                //返回置顶的音乐
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = ConnectionString();
                //conn.Open();
                DataSet ds=new DataSet();
                SqlCommand u = new SqlCommand();
                u.CommandText = "sp_Pagination";//调用存储过程
                u.CommandType = CommandType.StoredProcedure;
                var _with1 = u.Parameters;
                _with1.AddWithValue("@Tables", "Music");
                _with1.AddWithValue("@PrimaryKey", "ID");
                _with1.AddWithValue("@Sort", "Tim desc,ID asc");
                _with1.AddWithValue("@CurrentPage", 1);
                _with1.AddWithValue("@PageSize", 8);
                _with1.AddWithValue("@Fields", "title,html");
                _with1.AddWithValue("@Filter", "IsTuijian=1"); //1即为推荐
                _with1.AddWithValue("@Group", "");
                SqlDataAdapter mySqlDatapter = new SqlDataAdapter();
                mySqlDatapter.SelectCommand = u;
                mySqlDatapter.Fill(ds);
                Int64 uCount=ds.Tables[0].Rows.Count;
                string code;
                code = null;
                if (uCount > 0)
                {
                    for (Int64 i=0; i <= uCount - 1;i++)
                    {
                        //var _with2 = ds.Tables[0].Rows[i];
                        code += ds.Tables[0].Rows[i]["html"].ToString() ;
                    }
                }
            }
      

  4.   

     Int64 uCount=ds.Tables[0].Rows.Count;
                string code;
                code = null;
                if (uCount > 0)
                {
                    for (Int64 i=0; i <= uCount - 1;i++)
                    {
                        //var _with2 = ds.Tables[0].Rows[i];
                        code += ds.Tables[0].Rows[i]["html"].ToString() ;
                    }
                }====================================================
    上面改为下面试下:string code = "";
    DataTable dt = ds.Table[0];
    foreach (DataRow dr in dtAnswers.Rows)

       code += dr["html"].ToString();
    }如果还出错,应该是上面那些有问题
      

  5.   


    给你说了好几遍了你连我的方法试都没试,囧:code += dr["html"].value.ToString();能直接cell.ToString()吗?
      

  6.   

    加上.value再加.ToString()不加.value的话你加的是DataGridView的Cell类型
    加上.value.Tostring才是单元格对应的值呵呵
    你加上试试,不对我再看你别的代码~~~~~
      

  7.   


    大哥,试过了呀,因为你说过的方法我也知道,我先就是按那么个方法做的。刚才又重新试了一次(.value.Tostring这个也试了,根本不存在.value这个项,更是直接报错),依旧报上边的错,是不是我的vs2008有问题?
      

  8.   

    你在用到ds.Tables[0].Rows[i]["html"].ToString()的地方设个断点看下ds阿
      

  9.   

    为什么会有“var”?VB.NET里面也不会有这个关键字吧……
      

  10.   

    var 新增的  汗~~~~~
      

  11.   


    大哥,vb.net(vs2008)里没var,我是把代码用vb.net写出来后转成c#后就有这个了
      

  12.   


    用vb.net写出来后转成c#后就有var了?你用什么转换的啊……推荐给你一款vb和C#互转的只能工具吧,很智能的
    http://www.developerfusion.com/tools/convert/vb-to-csharp/看看能否解决你的问题
      

  13.   

    那你把原先的VB.NET代码贴一下
      

  14.   


    我原来的vb.net的代码是没有问题的,因为是可以正常执行的,而转了之后却是无法编译通过的~
      

  15.   


    public Function getTopMusic() as string
       Dim conn as new sqlconnection
       conn.connectionstring=ConnectionString()
       conn.open()
       Dim ds as new DataSet
       Dim u as new sqlcommand
       u.commandtext="sp_Pagination"
       u.commandtype=CommandType.StoredProcedure
       with u.Parameters
          .AddWithValue("@Tables", "Music")
          .AddWithValue("@PrimaryKey", "ID")
          .AddWithValue("@Sort", "Tim desc,ID asc")
          .AddWithValue("@CurrentPage", 1)
          .AddWithValue("@PageSize", 8)
          .AddWithValue("@Filter", "IsTuijian=1")
          .AddWithValue("@Group", "")
       End with
       Dim mySqlDapter as new SqlDapter
       mySqlDapter.Selectcommand=u
       mySqlDapter.Fill(ds)
       dim uCount as integer=ds.Tables(0).Rows.Count
       Dim Code as string=""
       if uCount>0 then
          for i as integer=0 to uCount-1
             with ds.Tables(0).Rows(i)
                code+=.Item("html")
             End with
          next
       End if ……End Function
      

  16.   

    找到原因了
    原来是因为我在for循环里把i定义成了int64,改成int了就没事了~分脏~