|
发表于 2007-10-9 20:59:13
|
显示全部楼层
VB.NET 源代码 不知道你要的是不是这个 ,如果是VB的化还要进行修改
Dim con As SqlConnection = New SqlConnection
Dim selectcommand As SqlCommand = New SqlCommand
Dim dataAdapter As SqlDataAdapter = New SqlDataAdapter
Dim ds As DataSet = New DataSet
dim message as string=""
'建立数据库连接
Public Sub GetConnected()
con.ConnectionString = "data source=(local)服务器名;initial catalog =ufdata_999_2007数据库名;user id=sa;password=SQL登陆密码"
con.Open()
End Sub
'查询函数
Public Sub GetData(ByRef ds As DataSet, ByRef message As String)
GetConnected()
'创建一个 selectCommand
selectcommand = New SqlCommand
selectcommand.CommandText = "select * from gl_accvouch"
selectcommand.Connection = con
ds = New DataSet
'创建一个DataAdapter
dataAdapter = New SqlDataAdapter
dataAdapter.SelectCommand = selectcommand
Try
dataAdapter.Fill(ds)
Catch ex As Exception
message = ex.Message.ToString
Finally
con.Close()
End Try
End Sub
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
getdata(ds,message)
if message="" then
medatagridview1.datasource=ds.tables(0) '把数据绑定到DATAGRIDVIEW控件
else
msgbox(message)
return
end if
End Sub
[ 本帖最后由 syy 于 2007-10-9 21:02 编辑 ] |
|