| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 968 人关注过本帖
标题:vb.net连接并操作mysql
只看楼主 加入收藏
wuj
Rank: 2
等 级:论坛游民
帖 子:11
专家分:14
注 册:2009-9-26
收藏
 问题点数:0 回复次数:2 
vb.net连接并操作mysql
连接并操作mysql ,最好有个实例,我是亲手,只是连接成功了,还不知道怎么操作,谢谢大家的帮助.
搜索更多相关主题的帖子: mysql 
2010-12-13 15:42
lhep041
Rank: 2
等 级:论坛游民
帖 子:7
专家分:20
注 册:2012-4-15
收藏
得分:0 
我也是个新手,一个高手给我写的一段参考,也供你参考下。

Imports MySql.Data.MySqlClient

Public Class Form1



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim m_strConnection As String = "server=192.9.200.59;uid=root;pwd=XXX;database=redboardppe; pooling=false"
        Dim m_SqlConn As MySqlConnection = New MySqlConnection(m_strConnection)


        Dim SQL As String

        SQL = "SELECT * FROM newtable"
        Dim daAdapter As MySqlDataAdapter = New MySqlDataAdapter(SQL, m_SqlConn)


        Dim myCmd As MySqlCommand
        myCmd = New MySqlCommand(SQL, m_SqlConn)

        daAdapter.SelectCommand = myCmd

        Dim myCbd As MySqlCommandBuilder

        myCbd = New MySqlCommandBuilder(daAdapter)

        Dim mySet As New DataSet()

        daAdapter.TableMappings.Add("newtable", "newtable")

        daAdapter.TableMappings(0).ColumnMappings.Add("id", "id")

        daAdapter.TableMappings(0).ColumnMappings.Add("name", "name")



        'Dim dsTable As DataTable = New DataTable("newtable")
        daAdapter.Fill(mySet)

        Dim dr As DataRow

        dr = mySet.Tables(0).NewRow()

        dr("name") = Me.TextBox2.Text ''  System.Guid.NewGuid().ToString()

        mySet.Tables(0).Rows.Add(dr)

        daAdapter.Update(mySet)



    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim m_strConnection As String = "server=192.9.200.59;uid=root;pwd=XXX;database=redboardppe; pooling=false"
        Dim m_SqlConn As MySqlConnection = New MySqlConnection(m_strConnection)


        Dim SQL As String

        SQL = "SELECT * FROM newtable"
        Dim daAdapter As MySqlDataAdapter = New MySqlDataAdapter(SQL, m_SqlConn)


        Dim myCmd As MySqlCommand
        myCmd = New MySqlCommand(SQL, m_SqlConn)

        daAdapter.SelectCommand = myCmd

        Dim myCbd As MySqlCommandBuilder

        myCbd = New MySqlCommandBuilder(daAdapter)

        Dim mySet As New DataSet()

        daAdapter.TableMappings.Add("newtable", "newtable")

        daAdapter.TableMappings(0).ColumnMappings.Add("id", "id")

        daAdapter.TableMappings(0).ColumnMappings.Add("name", "name")



        'Dim dsTable As DataTable = New DataTable("newtable")
        daAdapter.Fill(mySet)

        For Each dr As DataRow In mySet.Tables(0).Rows
            dr("name") = Me.TextBox1.Text
        Next

        daAdapter.Update(mySet)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim m_strConnection As String = "server=192.9.200.59;uid=root;pwd=XXX;database=redboardppe; pooling=false"
        Dim m_SqlConn As MySqlConnection = New MySqlConnection(m_strConnection)


        Dim SQL As String

        SQL = "delete FROM newtable"
        Dim daAdapter As MySqlDataAdapter = New MySqlDataAdapter(SQL, m_SqlConn)


        Dim myCmd As MySqlCommand
        myCmd = New MySqlCommand(SQL, m_SqlConn)

        daAdapter.SelectCommand = myCmd
        m_SqlConn.Open()
        myCmd.ExecuteNonQuery()

        m_SqlConn.Close()

    End Sub
End Class


[ 本帖最后由 lhep041 于 2012-4-16 09:00 编辑 ]
2012-04-16 08:56
wuj
Rank: 2
等 级:论坛游民
帖 子:11
专家分:14
注 册:2009-9-26
收藏
得分:0 
谢了
2012-09-12 18:28
快速回复:vb.net连接并操作mysql
数据加载中...
 
   



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

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