帮我看看菜鸟
代码?? 这是我新建的类DataBase
sql Imports Sy
stem Imports Sy
stem.Data Imports Sy
stem.Data.
sqlClient Public Class DataBase
sql Public Conn As
sqlConnection Public ds As DataSet Public da As
sqlDataAdapter Public Comm As
sqlCommand Public Str_Con As String 打开
数据库连接 Public Overloads Function DB
open() As Sy
stem.Data.
sqlClient.
sqlConnection Str_Con = server = ;uid=sa;pwd= ;database =gl Str_Con = Integrated S
ecurity=
sspI;Persist S
ecurity Info=False;Initial Catalog=gl Try Conn = New
sqlConnection(Str_Con) Conn.
open() DBOpen = Conn Return Conn Catch ex As Exception Conn =
nothing Message
Box.Show(ex.ToString) End Try End Function
关闭数据库连接 Public Overloads Function DBClose() As Boolean Try Conn.Close() Conn =
nothing Catch ex As Exception Message
Box.Show(ex.ToString) End Try End Function 填充数据 Public Function DBDataGridView(ByVal str_cmd As String,ByVal datagv As DataGridView) As String Try da = New
sqlDataAdapter(str_cmd,Conn) ds = New DataSet da.Fill(ds) datagv.DataSource = ds.Tables Catch ex As Exception Message
Box.Show(ex.ToString) End Try End Function End Class 我在
页面中
调用为 Public Db
sql As New DataBase
sql Private Sub Form1_Load(ByVal sender As Sy
stem.Object,ByVal e As Sy
stem.EventArgs) Handles MyBase.Load Dim str As String str = select * from tb_vi Db
sql.DB
open() Db
sql.DBDataGridView(str,DataGridView1) Db
sql.DBClose() End Sub 为什么在DataGridView1不能
显示数据了 。。。 __________________________________________________________________________ 填充数据 Public Function DBDataGridView(ByVal str_cmd As String,Conn) ds = New DataSet da.Fill(ds) datagv.DataSource = ds.Tables datagv.DataBind() //LZ上了
一个哦 , C#是datagv.databind(),不知道VB是否也是这样用的! Catch ex As Exception Message
Box.Show(ex.ToString) End Try End Function End Class __________________________________________________________________________ vb.net好像不要绑定哦 __________________________________________________________________________ vb.net好像不要绑定哦 __________________________________________________________________________ Public Function DBDataGridView(ByVal str_cmd As String,ByVal datagv As DataGridView) As String//---返回值? Try da = New
sqlDataAdapter(str_cmd,Conn) ds = New DataSet da.Fill(ds) datagv.DataSource = ds.Tables//這句是得不到數據源的 改成: datagv.DataSource=ds.Tables(0) 或者: datagv.DataSource=ds.Tables datagv.DataMember=ds.Tables(0).TableName Catch ex As Exception Message
Box.Show(ex.ToString) End Try End Function __________________________________________________________________________ 楼上正确。Tables是
一个众多DataTable对象的集合,Tables(0)才是
一个DataTable对象。 __________________________________________________________________________
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。