菜鸟提问 关于在VB.NET中使用SQL语句的简单问题(在线等待,本人刚刚注册账号,所以分数有限,20分,解决立即结贴)

zhaofangbao 2004-11-21 03:26:30
Dim ccount As interger
DataGrid1.DataSource = rs
SqlDataAdapter1.Fill(rs)

ccount = "Select Count (*) from ws_User"
MsgBox(ccount)

我想取出数据库里共有多少条记录,可这样显示出来不是数据库中的记录数,而是"Select Count (*) from ws_User",向各位大侠请教。
...全文
145 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
minmin071400 2004-11-22
  • 打赏
  • 举报
回复
msgbox(datagrid.rows)
zhangfanfly 2004-11-22
  • 打赏
  • 举报
回复
dim con as string
dim com as string

con = "data source = xxx;initial catalog = xxx;user id = xxx;password = xxx"
com = "select....."

dim a as new sqldataadapter(com,con)
dim table as new datatable

try
a.fill(table)
me.datagrid1.datasource = table
catch ex as exception
console.writeline(ex.tostring)
end try

用msdn帮助就可以了,挺全的
zhaofangbao 2004-11-22
  • 打赏
  • 举报
回复
各位大侠们有没有关于VB.net实例代码的好网址呀?
misng 2004-11-21
  • 打赏
  • 举报
回复
Dim conString As String = "Persist Security Info=False;Data Source=localhost;Initial Catalog=DB;User ID=sa;Password =''"
strSelect="Select Count (*) as number from ws_User"
Dim Conn As SqlConnection = New SqlConnection(conString)

Dim cmd As SqlCommand = New SqlCommand(strSelect, Conn)
Dim Da As SqlDataAdapter = New SqlDataAdapter
Da.SelectCommand = cmd
Dim ds As DataSet = New DataSet
Dim ccount As interger
Try

Conn.Open()
Da.Fill(ds, "nTable")
if ds.Table(0).rows.count>0 then
ccount=ds.Table(0).rows(0).Item("Number")
endif
Catch ex As Exception
'MsgBox("数据打开失败", 64, "天晴提示")
End Try
MessageBox.Show(ccount);
水如烟 2004-11-21
  • 打赏
  • 举报
回复
SqlCommand.ExecuteScalar
执行查询,并返回查询所返回的结果集中第一行的第一列。忽略额外的列或行。
zhaofangbao 2004-11-21
  • 打赏
  • 举报
回复
多谢各位帮助!
DataGrid1.DataSource = rs
SqlDataAdapter1.Fill(rs)
这两句是能过组件连接到数据库之后生成的,
我想把这个数据库中某个表的记录总数查询出来,
不知道代码怎么写?
上面我写的那些SQL语句没有执行,这是为什么呀?
本人是超级菜菜鸟呀,请各位大侠多多帮忙!
希望大家能直接给我VB.net中的代码!
waterjkd 2004-11-21
  • 打赏
  • 举报
回复
SQL 没执行吧
greennetboy 2004-11-21
  • 打赏
  • 举报
回复
这样写是做什么呀?我搞不明白你想msgBox什么消息,如果你想显示"Select Count (*) from ws_User"
但中间几行代码作什么用?如果是显示记录数,这样不是差太多了么? 可以参考代码(C#)
SqlDataAdapter ad=new SqlDataAdapter("SELECT COUNT (*) FROM ws_user",Con);//Con为SqlConnection,用于连接数据库
DataSet ds=new DataSet();
ad.Fill(ds,"ws_user");
string ccount=ds.Tables["ws_user"].Rows[0].ItemArray[0].toString();
MessageBox.Show(ccount);

16,554

社区成员

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

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