0
我有一個名爲lblHours的標籤,如何將下面的SQL語句的結果放入此標籤中?將SQL語句的結果放入標籤
Dim SqlQuery1 As String = "SELECT SUM(Hours) FROM TimeSheet WHERE StaffID='" &
cbStaffID.Text & "' AND TimeSheetMonth='" & cbMonth.Text & "'"
我有一個名爲lblHours的標籤,如何將下面的SQL語句的結果放入此標籤中?將SQL語句的結果放入標籤
Dim SqlQuery1 As String = "SELECT SUM(Hours) FROM TimeSheet WHERE StaffID='" &
cbStaffID.Text & "' AND TimeSheetMonth='" & cbMonth.Text & "'"
一個例子
Dim con As SqlConnection = "your Connection String"
Dim cmd As SqlCommand
Dim query As String = "SELECT SUM(Hours) FROM TimeSheet WHERE StaffID='" &
cbStaffID.Text & "' AND TimeSheetMonth='" & cbMonth.Text & "'"
cmd = New SqlCommand(query, con)
Try
con.open
Dim myreader As SqlDataReader = cmd.ExecuteReader()
If myreader.Read() Then
yourlable.text = myreader.GetValue(0)
End If
myreader.Close()
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
con.Close()
有幾種不同的方法,你可以去這個問題。
此Microsoft文章介紹瞭如何使用OLEDB連接到Access數據庫...
http://support.microsoft.com/kb/821765
這就是去了解它的一種方式。還有其他方法可以連接到Access數據庫;你需要做一些基礎研究。