『壹』 vb.net和mysql本地資料庫連接
直接在代碼里連接就可以啦。
首先本地的資料庫要啟動起來。然後直接再點net里的配置文件里配置資料庫的訪問,然後就可以發文了資料庫的地址,用戶名和密碼。
『貳』 求用vb.net寫一個讀取資料庫數據的簡單操作。
Option Explicit On
Option Strict On
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Program
Public Shared Sub Main()
Dim connectionString As String = _
"Data Source=(local);Initial Catalog=Northwind;" _
& "Integrated Security=true"
' Provide the query string with a parameter placeholder.
Dim queryString As String = _
"SELECT ProctID, UnitPrice, ProctName from dbo.Procts " _
& "WHERE UnitPrice > @pricePoint " _
& "ORDER BY UnitPrice DESC;"
' Specify the parameter value.
Dim paramValue As Integer = 5
' Create and open the connection in a using block. This
' ensures that all resources will be closed and disposed
' when the code exits.
Using connection As New SqlConnection(connectionString)
' Create the Command and Parameter objects.
Dim command As New SqlCommand(queryString, connection)
command.Parameters.AddWithValue("@pricePoint", paramValue)
' Open the connection in a try/catch block.
' Create and execute the DataReader, writing the result
' set to the console window.
Try
connection.Open()
Dim dataReader As SqlDataReader = _
command.ExecuteReader()
Do While dataReader.Read()
Console.WriteLine( _
vbTab & "{0}" & vbTab & "{1}" & vbTab & "{2}", _
dataReader(0), dataReader(1), dataReader(2))
Loop
dataReader.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.ReadLine()
End Using
End Sub
End Class
這是我在vs2010中微軟自帶的MSDN示例代碼裡面拷的,是關於ADO.net連接sql的操作。
希望對你有幫助。 如果你還需要其他的,我也可以再拷給你看。