Visual Basic 2010 DataSet

与世无争的帅哥 提交于 2020-01-17 01:18:18

问题


I'm using Visual Studio 2010 and I'm working on a windows application form. I'm struggling with our database. I can connect and retrieve Data in the Grid View.

But I don't want to display the records - I want to put a specific row column in a variable (in short I want to work with it). My DataSet is called ProductionDataSet. The Table is called Employee and has four columns called Employee, First_Name, Last_Name and Status.

How do I now store lets say the entry in column 4 and row 5 in the variable x?


回答1:


After you connect to the databse you need to put the data into a DataTable and then manipulate the Row Items

' DataSet/DataTable variables
Dim ProductionDataSet As New DataSet
Dim dtProductionDataTable As New DataTable
Dim daProductionDataAdapter As New OdbcDataAdapter

' Variables for retrieved data
Dim sEmployee As String = ""
Dim sFirstName As String = ""
Dim sSurname As String = ""
Dim sStatus As String = ""

'Connect to the database 
''

'Fill DataSet and assign to DataTable
 daProductionDataAdapter.Fill(ProductionDataSet , "ProductionDataSet")
 dtProductionDataTable = ProductionDataSet.Tables(0)

'Extract data from DataTable
' Rows is the row of the datatable, item is the column

 sEmployee  = dtProductionDataTable.Rows(0).Item(0).ToString
 sFirstName  = dtProductionDataTable.Rows(0).Item(1).ToString
 sSurname  = dtProductionDataTable.Rows(0).Item(2).ToString
 sStatus  = dtProductionDataTable.Rows(0).Item(3).ToString


来源:https://stackoverflow.com/questions/7446514/visual-basic-2010-dataset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!