怎么取得这个数据值?

希偌 2002-07-22 03:06:38
………………
public int Dg() {
SqlDataAdapter sda = new SqlDataAdapter("select count(*) from bbs1", myConnection);
sda.Fill(ds);
int c=这里应该怎么写,才能得到count的值;//如果不用this.ds.Tables[0].Rows.Count
return(c);
}
……………………
...全文
35 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljjhm 2002-07-22
  • 打赏
  • 举报
回复
怎么还可以回贴
htouch 2002-07-22
  • 打赏
  • 举报
回复
int count=0;
SqlCommand myCommand = new SqlCommand("select count(*) from bbs1", myConnection);
myConnection.Open();
SqlDataReader reader = myCommand.ExecuteReader();
while(reader.Read())
{
count = (int)reader[0];
}
ljjhm 2002-07-22
  • 打赏
  • 举报
回复
错!!!了!!!
最后一句改为:
int c=MyReader.GetInt32(0);
ljjhm 2002-07-22
  • 打赏
  • 举报
回复
string sql="select count(*) from screcord";
SqlCommand myCmd = new SqlCommand ("select count(*) from screcord",myConn);
myConn.open();
SqlDataReader MyReader=myCmd.ExecuteReader();
int c=myCmd.GetInt32(0);
spring_ok 2002-07-22
  • 打赏
  • 举报
回复
Agree.

int c = System.Convert.ToInt32(myCmd.ExecuteScalar());
hgknight 2002-07-22
  • 打赏
  • 举报
回复
The Better Way is——
public int Dg() {
OleDbCommand myCmd = new OleDbCommand("select count(*) from screcord",myConn);
int c=int.Parse(myCmd.ExecuteScalar().ToString());
return(c);

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧