2016-12-26 51 views
0

我正在开发使用vb.net的应用程序,记录在ms访问中的所有信息。任何人都可以教我如何从数据表中的第一行的第一列和第二列获取信息以便在文本框中显示。如何显示数据表中的信息?

这是我试过的代码,当然它没有工作,因为我希望它是。

Dim cmd As New OleDbCommand("Select Sum([SharkTWbySpecies]), Sum([RayTWbySpecies]) From TWbySpecies Where [OperationID] =" & TextBoxOpID4.Text, myConnection) 
    Dim AllSampleTW As Integer = cmd.ExecuteNonQuery() 
    TextBoxAllSharkSampleTW.Text = AllSampleTW.ToString() 
    TextBoxAllRaySampleTW.Text = AllSampleTW.ToString() 

希望有人能帮助我。谢谢!

回答

0

使用DataReader去取data.FYI,使用参数化查询,以避免sql injection

 Dim cmd As New OleDbCommand("Select Sum([SharkTWbySpecies]), Sum([RayTWbySpecies]) From TWbySpecies Where [OperationID] [email protected]", myConnection) 
     cmd.Parameters.AddWithValue("@val", TextBoxOpID4.Text) 
     Dim dr As OleDbDataReader = cmd.ExecuteReader 
     If dr.HasRows Then 
      While dr.Read ' loop through the datareader and get values of each column 
       TextBoxAllSharkSampleTW.Text = dr(0) 
       TextBoxAllRaySampleTW.Text = dr(1) 
      End While 
     End If 
+0

非常感谢!它按我的预期工作。 – lee

相关问题