vb.net 读取数据库
时间: 2023-09-14 15:04:42 浏览: 169
您好!感谢您对ChitGPT的使用。针对您的问题,可以使用以下代码来实现VB.NET读取数据库:
```
Dim connectionString As String = "Data Source=serverName;Initial Catalog=DBName;User ID=userID;Password=password"
Dim connection As New SqlConnection(connectionString)
Dim sql As String = "SELECT * FROM TableName"
Dim command As New SqlCommand(sql, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
While reader.Read()
Dim column1 As String = reader.GetString(0)
Dim column2 As Integer = reader.GetInt32(1)
'读取其他列'
End While
connection.Close()
```
请注意替换数据源、数据库名称、用户名和密码以及表名称和列名,在使用之前请确保已安装适当的数据库驱动程序。希望这可以帮助您解决您的问题!
阅读全文