Vb.net – Visual Basic 2010 DataSet

ado.netdatasetvb.net

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?

Best Answer

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
Related Topic