怎么返回数据集合的条数的啊!里面有程序,请各位看看啊!!!!!!

jsjhj2008 2007-12-06 09:41:18

try
{
string strsql= "SELECT * FROM yh WHERE yh='";
strsql += this.textBox1.Text + "' AND mm='";
strsql += this.textBox2.Text + "'";
this.sqlCommand1.CommandText = strsql;
this.sqlCommand1.Connection = this.sqlConnection1;
this.sqlConnection1.Open();
this.sqlCommand1.ExecuteNonQuery();
this.sqlConnection1.Close();
this.sqlDataAdapter1.Fill(this.dataSet1, "yh");
int a= this.dataSet1.Tables["yh"].Rows.Count;
MessageBox.Show(a.ToString());
}
catch(Exception Err)
{
MessageBox.Show("更新数据库记录操作失败:"+Err.Message,"信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
//如果打开了连接,则关闭它
if(this.sqlConnection1.State==ConnectionState.Open)
{
this.sqlConnection1.Close();
}
}
我定义的a返回不出我查询得到记录的行数,请大家帮我看看啊
...全文
111 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hutusoft 2007-12-07
  • 打赏
  • 举报
回复
this.sqlConnection1.Close();
this.sqlDataAdapter1.Fill(
你Connection 都关闭掉了,怎样使用DataAdapter填充数据。
填充前不能关,填充后再关。

t88266236 2007-12-07
  • 打赏
  • 举报
回复
ExecuteNonQuery一般用于更新数据库,正如名字所说,它不会返回数据集
MSDN:
public abstract int ExecuteNonQuery ()
返回值
受影响的行数。
t88266236 2007-12-07
  • 打赏
  • 举报
回复
sql直接用count吧 然后用executeScalar()来返回.
aywxj 2007-12-07
  • 打赏
  • 举报
回复
这样试一下:


try
{
string strsql= "SELECT * FROM yh WHERE yh='";
strsql += this.textBox1.Text + "' AND mm='";
strsql += this.textBox2.Text + "'";

this.sqlConnection1.Open();
this.sqlDataAdapter=new SqlDataAdapter(strsql,sqlConnection1);



this.sqlDataAdapter1.Fill(this.dataSet1, "yh");
this.sqlConnection1.Close();
int a= this.dataSet1.Tables["yh"].Rows.Count;
MessageBox.Show(a.ToString());
}
catch(Exception Err)
{
MessageBox.Show("更新数据库记录操作失败:"+Err.Message,"信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
//如果打开了连接,则关闭它
if(this.sqlConnection1.State==ConnectionState.Open)
{
this.sqlConnection1.Close();
}
}
我定义的a返回不出我查询得到记录的行数,请大家帮我看看啊
publina 2007-12-07
  • 打赏
  • 举报
回复
this.dataSet1
在哪里赋了查询结果?
你应该只是定义了一下吧。
symbol441 2007-12-07
  • 打赏
  • 举报
回复
this.sqlDataAdapter1.Fill(this.dataSet1, "yh");
int a= this.dataSet1.Tables["yh"].Rows.Count;
MessageBox.Show(a.ToString());
------------------------
没有看懂.楼主的sqlDataAdapter1是从那里来的?
你的dataSet1.table["yh"]中是否是确有值的?
wdd000 2007-12-07
  • 打赏
  • 举报
回复
没有使用sqlConnection1 去创建sqlDataAdapter1的实例 而且使用的 this.sqlCommand1.ExecuteNonQuery();
返回的整形 不能填充数据集的.
jsjhj2008 2007-12-07
  • 打赏
  • 举报
回复
你好aywxj
你的程序对了谢谢啊
armipotence 2007-12-06
  • 打赏
  • 举报
回复
代码有问题
bindian 2007-12-06
  • 打赏
  • 举报
回复
将记录集存放到一个集合中,如ArrayList集合中,这样通过ArrayList的count属性就可以得到查询得到记录的行数

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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