[VB.NET]VB2005+ACCESS中,如何获得select count(1) from tb的返回值?

前端之家收集整理的这篇文章主要介绍了[VB.NET]VB2005+ACCESS中,如何获得select count(1) from tb的返回值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
VB2005+ACCESS中,如何获得select count(1) from tb的返回值? 我想取得某table的行数,用的方法如下,希望大家能帮我补充/纠正下: Dim MyConnection As New OleDbConnection(...) Dim sqlString As String = "SELECT * FROM table " MyConnection.Open() MyCommand = New OleDbCommand(sqlString,MyConnection) Dim CountString As String = "SELECT count(1) FROM table " & " WHERE ... " MyCommand.CommandText = CountString MyCommand.Connection = MyConnection Dim RowCounts As Integer RowCounts =??? ''我用=MyCommand.ExecuteNonQuery()试了下,不行,msdn找不到,就上来问问了,谢过了啊~ __________________________________________________________________________ 还有不知道其它更好的方法是怎么样的,期待^ __________________________________________________________________________ SELECT count(ID) FROM table " & " WHERE ... " ID 为其中一列的列名 __________________________________________________________________________ 错了,不好意思 __________________________________________________________________________ 是不是这个sql语句: Dim CountString As String = "SELECT count(1) FROM table " & " WHERE ... " 在 count(1) as 表达式1 完整的写一下: Dim CountString As String = "SELECT count(1) as 表达式1 FROM table " & " WHERE ... " __________________________________________________________________________ 返回一个值,不该用这个方法ExecuteNonQuery,应该用这个方法: ExecuteScalar __________________________________________________________________________ 修改你的代码 Dim CountString As String = "SELECT count(1) as 表达式1 FROM table " & " WHERE ... " …… …… RowCounts =MyCommand.ExecuteScalar ''这里应该用.ExecuteScalar MSND上说: MyCommand.ExecuteScalar是“执行查询,并返回查询所返回的结果集中第一行的第一列” MyCommand.ExecuteNonQuery()是“对连接对象执行 sql 语句” 它没有返回值 我刚刚测试过 __________________________________________________________________________ zxypy() 表达式1该填什么? (本人新手见怪了) __________________________________________________________________________ 表达式1 就是任意一个变量 什么都行,只要是不是VB关键字、不是数字开头、不包涵空格……,汉字都行。比如:MYSumCount __________________________________________________________________________ 表达式1 就是任意一个变量 什么都行,只要是不是sql关键字、不是数字开头、不包涵空格……,汉字都行。比如:MYSumCount 上一个我写错了个VB,应是sql __________________________________________________________________________ 原来这里的表达式1 留空也可以,谢谢各位参与 __________________________________________________________________________ 对了还有ExecuteNonQuery() MSDN上说的是返回影响的行数~ __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/264028.html

猜你在找的VB相关文章