sql:select count(*) from Tab 执行后获得一个dataset,int n=Convert.ToInt32(DataSet1.Tables[0].Rows[0][0]);
用rs.recordcount来得到纪录个数
楼上的,你说的是ADO,现在是ADO.NET了!
这样可以吗? String SQL="Select count(*) from soccer_exchange where user_id=@user_id and state=1"; DataSet ds=new DataSet(); SqlDataAdapter Adapter=new SqlDataAdapter(SQL,Conn); Adapter.Fill(ds,"count"); int n = ds.Tables["count"].Rows.Count;
不好意思发错了 String SQL="Select count(*) from soccer_exchange where user_id=@user_id and state=1"; cmd.Parameters.Add(new SqlParameter("@user_id",SqlDbType.Int,4)); cmd.Parameters["@user_id"].Value =user_id; DataSet ds=new DataSet(); SqlDataAdapter Adapter=new SqlDataAdapter(SQL,Conn); Adapter.Fill(ds,"count"); int n =Convert.ToInt32(ds.Tables[0].Rows[0][0]); 这样效率高吗?
</ItemTemplate> </asp:TemplateColumn>问题2: String SQL="Select count(*) from soccer_exchange where user_id=@user_id and state=1";SqlCommand cmd = new SqlCommand(SQL, Conn); conn.Open(); int n = Int32.Parese(cmd.ExecuteScalar());conn.Close();
关于第一个问题,为什么不把[万]字放在页眉上! 第二个问题 如果你单单要获取个数,同时不查询数据的话 String SQL="Select count(id) from soccer_exchange where user_id=@user_id and state=1";SqlCommand cmd = new SqlCommand(SQL, Conn); conn.Open(); int n = Int32.Parese(cmd.ExecuteScalar());conn.Close(); 否则就用你自己的方法
查询一个表里面该用户的拥有的球员个数
我知道好象用(count)
那查询后怎么把结果拿出来付给n啊
执行后获得一个dataset,int n=Convert.ToInt32(DataSet1.Tables[0].Rows[0][0]);
String SQL="Select count(*) from soccer_exchange where user_id=@user_id and state=1";
DataSet ds=new DataSet();
SqlDataAdapter Adapter=new SqlDataAdapter(SQL,Conn);
Adapter.Fill(ds,"count");
int n = ds.Tables["count"].Rows.Count;
String SQL="Select count(*) from soccer_exchange where user_id=@user_id and state=1";
cmd.Parameters.Add(new SqlParameter("@user_id",SqlDbType.Int,4));
cmd.Parameters["@user_id"].Value =user_id;
DataSet ds=new DataSet();
SqlDataAdapter Adapter=new SqlDataAdapter(SQL,Conn);
Adapter.Fill(ds,"count");
int n =Convert.ToInt32(ds.Tables[0].Rows[0][0]);
这样效率高吗?
<ItemTemplate>
<%# (int)DataBinder.Eval(Container.DataItem,"worth")>10000?DataBinder.Eval(Container.DataItem,"worth")+"<FONT color=\"black\" size=\"3\">万</FONT>":DataBinder.Eval(Container.DataItem,"worth")%>
</ItemTemplate>
</asp:TemplateColumn>问题2:
String SQL="Select count(*) from soccer_exchange where user_id=@user_id and state=1";SqlCommand cmd = new SqlCommand(SQL, Conn);
conn.Open();
int n = Int32.Parese(cmd.ExecuteScalar());conn.Close();
第二个问题
如果你单单要获取个数,同时不查询数据的话
String SQL="Select count(id) from soccer_exchange where user_id=@user_id and state=1";SqlCommand cmd = new SqlCommand(SQL, Conn);
conn.Open();
int n = Int32.Parese(cmd.ExecuteScalar());conn.Close();
否则就用你自己的方法