在 VB.NET 中获取 SQL Server 表中的行数
primary_student_table
有10行.
当我执行下面的代码时,结果是-1.
When I execute the following code, the result was -1.
Dim count As Int16
con.Open()
query = "SELECT COUNT(roll) AS rollcount FROM primary_student_table WHERE admityear = 2011 AND batch = 1 "
cmd = New SqlCommand(query, con)
count = cmd.ExecuteNonQuery
MsgBox(count)
con.Close()
以上代码有什么问题?
推荐答案
解决办法是替换
count = cmd.ExecuteNonQuery
与
count = cmd.ExecuteScalar
就像罗伯特·博比恩在他的评论中所说的那样
Like Robert Beaubien said in his comments
相关文章