在VB.NET中获取SQL Server表中的行数 [英] Get number of rows in a SQL Server table in VB.NET

查看:461
本文介绍了在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()

上面的代码有什么问题?

What's the problem in the above code?

推荐答案

解决方案是替换

count = cmd.ExecuteNonQuery

with

count = cmd.ExecuteScalar 

像Robert博比恩在评论中说

Like Robert Beaubien said in his comments

这篇关于在VB.NET中获取SQL Server表中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆