string strSql = "select id from ComputerAd order by id desc";
SqlCommand LoadCMD = new SqlCommand(SqlLoad, MyConnection);
SqlDataAdapter adapter = new SqlDataAdapter(SqlLoad,MyConnection);
adapter.SelectCommand = LoadCMD;我想问一下 怎么把第一行的id值 取出来
然后付到 int id上去 谢谢

解决方案 »

  1.   

    string strSql = "select id from ComputerAd order by id desc";
    SqlCommand LoadCMD = new SqlCommand(SqlLoad, MyConnection);
    SqlDataReader reader = LoadCMD.ExecuteReader()
    while(reader.Read())
    {
        id = (int)reader["ID"];
    }
    reader.Close();
    MyConnection.Close()
      

  2.   

    DataSet ds=new DataSet();
    string strSql = "select id from ComputerAd order by id desc";
    SqlDataAdapter adapter = new SqlDataAdapter(strSql,MyConnection);
    MyConnection.Open();
    adapter.Fill(ds,"ComputerAd");int id = Convert.ToInt32(ds.Tables["ComputerAd"].Rows[1]["id"]);部分语法再检查一下
      

  3.   

    int id = Convert.ToInt32(ds.Tables["ComputerAd"].Rows[1]["id"]);
    好象不对啊
    怎么改都报错
      

  4.   

    int id=Convert.ToInt32(dt.Tables["ComputerAd"].Rows[0][0].ToString());
      

  5.   

    ds.Tables["ComputerAd"] 函数“ds.Tables.get_Item”已求值并返回空
    ds.Tables["ComputerAd"].Rows[0].toString() 错误:“ds.Tables["ComputerAd"].Rows”不存在
    老大们 不对啊 痛苦中。。
      

  6.   

    SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");SqlCommand selectCMD = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn);
    selectCMD.CommandTimeout = 30;SqlDataAdapter custDA = new SqlDataAdapter();
    custDA.SelectCommand = selectCMD;nwindConn.Open();DataSet custDS = new DataSet();
    custDA.Fill(custDS, "Customers");nwindConn.Close();上面是填充ds的例子取数据之前,判断ds是否为空
    if (DS != null && DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
    {
        int id = Convert.ToInt32(DS.Tables[0].Rows[0]["id"]);
    }