在VB中读取SQL数据库数据可以使用ADO.NET技术。以下是一个简单示例代码:
Imports System.Data.SqlClient
Dim connStr As String = "Data Source=myServerAddress;Initial Catalog=myDatabase;User ID=myUsername;Password=myPassword;"
Dim conn As New SqlConnection(connStr)
conn.Open()
Dim query As String = "SELECT * FROM myTable"
Dim cmd As New SqlCommand(query, conn)
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
Dim value1 As String = reader("column1").ToString()
Dim value2 As Integer = CInt(reader("column2"))
'处理读取到的数据
End While
reader.Close()
conn.Close()
conn.Dispose()
以上示例代码演示了如何连接到数据库,执行查询语句并读取数据。在实际应用中,可以根据具体需求修改查询语句和处理读取数据的逻辑。