如何用wamp mysql连接vb [英] how to connect vb with wamp mysql

查看:77
本文介绍了如何用wamp mysql连接vb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调用模块,以便vb中的每个表单都可以访问数据库而无需键入长代码和每个表单.该代码是否可用于模块,以及是否可以连接到数据库.或有其他解决方案?
谢谢,我感谢您的帮助


how to call for the module so that each form in vb can access the database without typing the long code and each form. whether the code can be used for module and can be or will not connect to database. or have other solution??
thanks and i appreciate for help


Option Strict On

Imports System.Data.SqlServerCe

Module Example

    Sub Main()
        Dim cs As String = "Database=apka;Data Source=localhost;" _
            & "User Id=root;Password="

        Dim stm As String = "SELECT VERSION()"
        Dim version As String
        Dim conn As MySqlConnection

        Try
            conn = New MySqlConnection(cs)
            conn.Open()

            Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)

            version = Convert.ToString(cmd.ExecuteScalar())

            Console.WriteLine("MySQL version: {0}", version)

        Catch ex As MySqlException
            Console.WriteLine("Error: " & ex.ToString())
        Finally
            conn.Close()
        End Try

    End Sub

End Module

推荐答案

在不更改为更好的设计模式的情况下,您可以大量搬出.
但是,这并不是一个坏主意:看看实现 3层架构 [ ^ ]-想法是移动数据访问完全脱离表单.
There isn''t a huge amount you can move out without changing to a better design pattern.
However, that wouldn''t be a bad idea: have a look at implementing a 3 Tier Architecture[^] - the idea being to move the data access away from your forms completely.


这篇关于如何用wamp mysql连接vb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆