| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 925 人关注过本帖
标题:Vb.net 自定连接数据库命名(1、OleDbConnection 2、OleDbDataAdapter 3、O ...
只看楼主 加入收藏
chxxnet
Rank: 2
等 级:论坛游民
帖 子:6
专家分:20
注 册:2010-3-31
结帖率:0
收藏
 问题点数:0 回复次数:0 
Vb.net 自定连接数据库命名(1、OleDbConnection 2、OleDbDataAdapter 3、OleDbCommand) 中文:连接、填充、数
编辑:lixainhui (chzy)
Public Class Form1
    Dim myDataSet As New DataSet   '自定数据集
    Dim strCom As String             '自定义数据集填充代码
    Dim oleDbConnection As OleDb.OleDbConnection        '自定连接代码
    Dim strConnect As String          '自定连接代码用来存放连接数据库路经!
    Private Sub oledbcon()
        '自定义数据库接代码!
        Dim strConnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\" & Me.TextBox1.Text & "\data\db1.mdb"
        OleDbConnection1 = New System.Data.OleDb.OleDbConnection(strConnect)
        OleDbConnection1.ConnectionString = strConnect
    End Sub
    Private Sub oledbdap()
        '自定义数据集填充代码!
        strCom = " SELECT * FROM tt"
        Dim myCommand As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(strCom, OleDbConnection1)
        myCommand.Fill(myDataSet, strCom)
    End Sub
    Dim cmd As New OleDb.OleDbCommand   '自定义连接命名代码
    Dim strSql As String                '自定义连接命名数据库表
    Private Sub oledbcom()
        '自定义COM命名代码!
        Dim cmd As New OleDb.OleDbCommand
        strSql = "SELECT * FROM tt"
         = strSql
        cmd.Connection = Me.OleDbConnection1
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            oledbcon()   '连接代码
            oledbdap()   '填充代码
            Me.OleDbConnection1.Open()
            Me.DataGrid1.DataSource = myDataSet
            Me.DataGrid1.DataMember = strCom
            'Me.DataGrid1.Select(Me.DataGrid1.CurrentRowIndex)
            Me.OleDbConnection1.Close()
        Catch ex As Exception
            MsgBox("数据库服务器未莲连接!请查正数据库服务器IP地址")
        End Try
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            oledbcon()    '连接代码
            Me.OleDbConnection1.Open()
            oledbcom()
            Dim cmdd As New OleDb.OleDbCommand(strSql, OleDbConnection1)
            Dim reader As OleDb.OleDbDataReader = cmdd.ExecuteReader()
            Dim hj As String
            Do While reader.Read
                If reader.Item("桌号") <> "" Then
                    hj = Val(hj) + Val(reader.Item("单价"))
                End If
            Loop
            Me.Label1.Text = "合计金额为:" & hj & "元"
            Me.OleDbConnection1.Close()
        Catch ex As Exception
        End Try
    End Sub
End Class
搜索更多相关主题的帖子: 填充 连接数据库 
2012-03-28 15:50
快速回复:Vb.net 自定连接数据库命名(1、OleDbConnection 2、OleDbDataAdapter ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.073639 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved