美好的一天。我正在尝试将数据从数据表显示到文本框控件。但是当程序运行时,我无法按下计算按钮。在此之前,我已尝试在datagridview控件上显示数据并显示。有没有人可以帮助我?非常感谢。
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
dataFile = "C:\Users\User\Documents\SharkRay Database.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select Sum([Shark Individual Weight]) From FishCaught Where [OperationID] =" & TextBoxOpID4.Text & " and [Scientific Name] ='" & ComboBoxSpeciesName2.SelectedItem & "'", myConnection)
Dim ds As DataTable = New DataTable()
da.Fill(ds)
TextBoxAllSharkTW.Text = ds.ToString()
myConnection.Close()
答案 0 :(得分:0)
试试这段代码。
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
dataFile = "C:\Users\User\Documents\SharkRay Database.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim cmd As New OleDb.OleDbCommand("Select Sum([Shark Individual Weight]) From FishCaught Where [OperationID] =" & TextBoxOpID4.Text & " and [Scientific Name] ='" & ComboBoxSpeciesName2.SelectedItem & "'", myConnection)
Dim count As Int32 = CInt(cmd.ExecuteScalar)
TextBoxAllSharkTW.Text = cstr(count)
myConnection.Close()
答案 1 :(得分:0)
Dim cmd As New OleDbCommand("Select Sum([Shark Individual Weight]) From FishCaught Where [OperationID] =" & TextBoxOpID4.Text & " and [Scientific Name] ='" & ComboBoxSpeciesName2.SelectedItem & "'", myConnection)
Dim count As Integer = cmd.ExecuteScalar()
TextBoxSharkTWbySpecies.Text = count.ToString()
cmd.Dispose()
myConnection.Close()
我对Shadow Fiend给出的代码做了一些修改,最后它有效!感谢。