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 t开发者_开发技巧he 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?
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
精彩评论