如何执行Sql 语句 获取返回值

zdebug 2008-03-31 11:23:52
如题~~~

sqlstr = "select count(*) as counts from Tablea where 1=1

请问我如何在vb.net 中执行这句话,并且得到我要的 counts 值,谢谢!!
...全文
284 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zdebug 2008-03-31
  • 打赏
  • 举报
回复
谢谢 lzmtw 、yellowdong 、guying999

lzmtw 你的代码可以
zdebug 2008-03-31
  • 打赏
  • 举报
回复
谢谢 lzmtw 我在试你的代码
zdebug 2008-03-31
  • 打赏
  • 举报
回复
请问我这句话怎么是错误的啊,错误是“是一个类型,不能用作表达式”

Convert(result,Int32)
yellowdong 2008-03-31
  • 打赏
  • 举报
回复
Dim conn As New SqlClient.SqlConnection("连接字符串")
Dim comm As New SqlClient.SqlCommand
dim str as string=""
try
conn.Open()
comm.Connection = conn
comm.CommandText = "select count(*) as counts from Tablea where 1=1 "
str=cmm.ExecuteScalar.tostring()
Catch ex As Exception
msgbox(ex.message)
cnn.Close()
comm.Dispose()
comm = Nothing
conn.Dispose()
conn = Nothing
End Try

水如烟 2008-03-31
  • 打赏
  • 举报
回复
        Dim cn As New SqlClient.SqlConnection("你的连接字串")
Dim cm As New SqlClient.SqlCommand("select count(*) as counts from Tablea", cn)
cn.Open()
Dim count As Integer = CType(cm.ExecuteScalar, Integer)
cn.Close()

cn.Dispose()
cm.Dispose()
guying999 2008-03-31
  • 打赏
  • 举报
回复
dim result as object
dim count as int

result = cm.ExecuteScalar()

If result not null then
count = Convert(result,Int32)
Else
count = 0
End If
zdebug 2008-03-31
  • 打赏
  • 举报
回复
能详细点嘛?

dim count as string

count = ?? cm.ExecuteScalar() ??? 这样可以??

谢谢~!
水如烟 2008-03-31
  • 打赏
  • 举报
回复
cm.ExecuteScalar()

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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