weixin_44774226
weixin_44774226
2019-05-30 09:32
采纳率: 100%
浏览 309

VB.net 查詢mysql 數據資料顯示到DataGridView1控件中,資料一直顯示不到DataGridView1中,我用的是ADOB

Dim Cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
'﹚竡ADODB
Dim strCn As String
Dim db_host As String
Dim db_user As String
Dim db_pass As String
Dim db_data As String
Dim i As Integer
' ﹚竡 SQL 粂
Dim sql As String
'计沮畐IP
db_host = "、、"
'姐腹
db_user = "、、"
'姐腹盞絏
db_pass = "、、"
'rs clode
'硈钡计沮畐
db_data = "Product"
strCn = "DRIVER={MySQL ODBC 5.3 ANSI Driver};" & _
"SERVER=" & db_host & ";" & _
"DATABASE=" & db_data & ";" & _
"UID=" & db_user & ";PWD=" & db_pass & ";" & _
"OPTION=3;stmt=SET NAMES UF8"
' 连接数据库
Cn.Open strCn
' 设置该属性, 使 recordcount 和 absolutepage 属性可用
Cn.CursorLocation = adUseClient
'' 访问表 zhanbie
sql = "select * from chanliang where gonghao='" & gonghao2.Text & "'

rs.Open sql, Cn

DataGridView1.DataSource=rs‘ 查詢到的資料顯示到控件DataGridView1中,也沒報錯,控件顯示空白

求大神幫幫~ 謝謝~

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • caozhy
    已采纳

    VB.NET不用ADO,用ADO.NET,用DataAdapter填充DataTable,将DataGridView1.DataSource绑定到DataTable上

    点赞 评论
  • weixin_44774226
    weixin_44774226 2019-05-30 16:42

    数据库更新,查询可以显示到编辑框内,但是就是不能显示到表格控件,

    点赞 评论

相关推荐