如何在vb中访问我的数据库中的值 我有一个名为Rates的表,其列具有PerMinute列和列Amount
我想访问金额列中的数据。并使它出现在AmountToPay.text上,请帮我新建数据库。
答案 0 :(得分:1)
编辑:
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim conStringBuilder = New OleDbConnectionStringBuilder
With conStringBuilder
' Path to your access db
.DataSource = "c:\db.accdb"
' For .mdb files change provider to Jet
' .Provider = "Microsoft.Jet.OLEDB.4.0"
.Provider = "Microsoft.ACE.OLEDB.12.0"
End With
Dim con As New OleDbConnection(conStringBuilder.ConnectionString)
Dim cmdString = "SELECT * FROM Rates"
Dim cmd As New OleDbCommand(cmdString, con)
Dim dTable As New DataTable
Try
con.Open()
Dim dReader = cmd.ExecuteReader
dTable.Load(dReader)
Catch ex As Exception
MsgBox(ex.Message)
End Try
' Output to console.
' You may want to set AmountToPay.text here
For Each dRow In dTable.Rows
Console.WriteLine(dRow("PerMinute"))
Console.WriteLine(dRow("Amount"))
Console.WriteLine()
Next
End Sub
End Module