偶好象记得一点,看对不对
连接数据库;
查询数据并填充到DS;
int i;
i=ds.Tables["表名"].Rows[0];
这样不对是吧,相应的代码该怎么写呢,请高手指教。谢谢!

解决方案 »

  1.   

    i=Convert.ToInt32(ds.Tables["表名"].Rows[0][0]);
    第一行的第一列
      

  2.   

    if(!IsPostBack)
    {
    string dsn = ConfigurationSettings.AppSettings["TRS"];
    SqlConnection myConnection = new SqlConnection(dsn);
    string mySelectQuery="select a.shopcode,a.shopname,a.shopchief,a.shopphone,a.shopfax, a.setupdate,a.memo,a.shopaddress,b.areaname from Shopdata as a left outer join area as b on a.areacode=b.areacode where a.ShopCode='"+ShopCode+"'";
    SqlCommand cmd=new SqlCommand(mySelectQuery,myConnection) ;
    myConnection.Open ();
    SqlDataReader dr=cmd.ExecuteReader();
    while(dr.Read())
    {
    lbCode.Text=dr["shopcode"].ToString();
    txtName.Text=dr["shopname"].ToString();
    txtChief.Text=dr["shopchief"].ToString();
    DateTimeBox1.Text =dr["setupdate"].ToString();
    ddlArea.SelectedItem.Text=dr["areaname"].ToString();
    txtAddress.Text=dr["shopaddress"].ToString();
    txtFax.Text=dr["shopfax"].ToString();
    txtMemo.Text=dr["memo"].ToString();
    txtPhone.Text =dr["shopphone"].ToString();
    }
    dr.Close ();
    cmd.Dispose ();
    myConnection.Close ();

    }这是我得赋值,希望楼主能用的上
      

  3.   

    string s = ds.Tables["表名"].Rows[0]["列名"].tostring();
    int i=System.convert.toint32(ds.Tables["表名"].Rows[0]["列名"].tostring());
      

  4.   

    SqlCommand.ExecuteScalar 方法 [C#]
    执行查询,并返回查询所返回的结果集中第一行的第一列。忽略额外的列或行。
    cmd.CommandText = "SELECT COUNT(*) FROM 表名 WHERE Sex='男'";
    Int32 count = (int32) cmd.ExecuteScalar();我的意思是说要用SqlCommand对象的ExecuteScalar 方法,sql语句假设是得到所有男生的人数:SELECT COUNT(*) FROM 表名 WHERE Sex='男'然后显示在页面上可以加个Label:
    Label1.Text=count.ToString();
      

  5.   

    string s=ds.Tables["表名"].Rows[0][0].ToString();然后转化再用
      

  6.   

    楼上的可以。
    也可以用enum得到Rows的值,然后赋予变量。
    IEnumerator a=dataSet1.Tables["表名"].DefaultView.Table.Rows.GetEnumerator();
    while(a.MoveNext())
    {
       row=(DataRow)a.Current;
       string i = row[1].ToString();
       ......
    }
      

  7.   

    string col=ds.Tables["表名"].Rows[0][0].ToString();
      

  8.   

    luckyTOTO(胡晓强)代码比较标准哦,shoutor(土人制造) 的代码可以实现了。
      

  9.   

    i=ds.Tables["表名"].Rows(0).item("列名")
      

  10.   

    int i=Convert.ToInt32(ds.Tables["TableName"].Rows[row][cell]);
      

  11.   


    晕,搞得这么麻烦,SqlCommand.ExecuteScalar 方法就返回一个值,连数据集都不用填充