主题:急救——请高手来帮一下忙
Dim objdataset As DataSet
Dim mydatatable As DataTable
'获得数据集的函数
(第一个参数是实际数据库中的表。第二个是数据库文件,第三个是“数据适配器添充数据表时的表名。”)
Public Function getdataset(ByVal mytable As String, ByVal mydb As String, ByVal strtable As String) As DataSet
Dim connstr, selectcmd As String
Dim conn As SqlConnection, myadapter As SqlDataAdapter
Try
connstr = "server=(local);database=" & mydb & ";integrated security=true"
selectcmd = "select * from" & mytable
Dim mydataset As New DataSet
conn = New SqlConnection(connstr)
myadapter = New SqlDataAdapter(selectcmd, conn)
myadapter.Fill(mydataset, strtable)
Return mydataset
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Sub displaydatatodbgrid() '读取数据到datagrid控件的方法
Try
objdataset = Me.getdataset("reader", "libmis", "reader")
mydatatable = objdataset.Tables("reader")
DataGrid1.DataSource = mydatatable
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub frmreader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.displaydatatodbgrid()
End Sub
请大家看看这些代码是否有错,若有的话,请帮我指出来。我实在不知它错在了哪?
第一个方法是得到数据集。
第二个是在数据网格控件中读出数据。(注,这个里面的数据集就是通过第一函数来完成的)
最后面的是个事件,载入事件,也就是显示窗体的时候,读出数据。
我的QQ:609745085
Dim mydatatable As DataTable
'获得数据集的函数
(第一个参数是实际数据库中的表。第二个是数据库文件,第三个是“数据适配器添充数据表时的表名。”)
Public Function getdataset(ByVal mytable As String, ByVal mydb As String, ByVal strtable As String) As DataSet
Dim connstr, selectcmd As String
Dim conn As SqlConnection, myadapter As SqlDataAdapter
Try
connstr = "server=(local);database=" & mydb & ";integrated security=true"
selectcmd = "select * from" & mytable
Dim mydataset As New DataSet
conn = New SqlConnection(connstr)
myadapter = New SqlDataAdapter(selectcmd, conn)
myadapter.Fill(mydataset, strtable)
Return mydataset
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Sub displaydatatodbgrid() '读取数据到datagrid控件的方法
Try
objdataset = Me.getdataset("reader", "libmis", "reader")
mydatatable = objdataset.Tables("reader")
DataGrid1.DataSource = mydatatable
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub frmreader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.displaydatatodbgrid()
End Sub
请大家看看这些代码是否有错,若有的话,请帮我指出来。我实在不知它错在了哪?
第一个方法是得到数据集。
第二个是在数据网格控件中读出数据。(注,这个里面的数据集就是通过第一函数来完成的)
最后面的是个事件,载入事件,也就是显示窗体的时候,读出数据。
我的QQ:609745085