string strSql = "select count(*) from rsm_frame where roomid='a1'";
我想获得执行这条SQL语句的返回值,请问应该用什么函数?

解决方案 »

  1.   

    SqlCommand com=new SqlCommand("select count(*) from rsm_frame where roomid='a1'",con);
    con.open()
    int count=(int)com.ExecuteScalar();
    con.close();
      

  2.   

    SqlCommand com=new SqlCommand("select count(*) from rsm_frame where roomid='a1'",con);
    con.open()
    object var=com.ExecuteScalar();
    if(var!=null)
    {
       int count=(int)com.ExecuteScalar();
    }con.close();
      

  3.   

        SqlConnection conns = WayDataBase.getConn();
                    conns.Open();                string whbc = dataGridView1.Rows[i].Cells["仓库代号"].Value.ToString();
                    string sqls = "select  minus_stk from tf_ij a left join my_wh b on b.wh=a.wh where a.wh='" + whbc + "' and b.dep='" + txtDept.Text + "'";
                    SqlCommand comms = new SqlCommand(sqls, conns);
                    string strwh = comms.ExecuteScalar().ToString();
                    if (strwh == "F")
                    {
                        MessageBox.Show("库存不足,禁止保存");
                        return;
                    }
                    comms.Dispose();
                    conns.Close();求解,我的取值不对