0

Using Microsoft's How to Guide, I have created a database within a word VSTO project. After this, I used another How to Guide to create a dataset from this database.

Now I am trying to get/set the data in the dataset's tables using the following Syntax from this Microsoft Concepts Page:

// This accesses the CustomerID column in the first row of the Customers table.
string customerIDValue = northwindDataSet.Customers[0].CustomerID;

Using this Syntax, my code is as follows:

string employeeName = _SOI_MasterDatabaseDataSet.JobPositionDataTable[0].EmployeeName;

This code gets an error saying that '_SOI_MasterDatebaseDataSet.JobPositionDataTable' is a type, which is not valid in the given context. (Syntax Error)

Here is a screenshot of my Data Sources as well.

This is the first time I've attempted to use databases/datasets. I'm not sure if this is a syntax error or if I've missed something while setting up the dataset in the Dataset Designer.

Thanks in advance

Lennart
  • 9,657
  • 16
  • 68
  • 84
Tullocco
  • 11
  • 5
  • Show us the code and errors messages. We don't want pictures of that stuff. – LarsTech Dec 05 '18 at 19:53
  • I don't work with the DataSet designer, but wouldn't it be `_SOI_MasterDatebaseDataSet.JobPosition[0].EmployeeName;`? – LarsTech Dec 05 '18 at 20:18
  • JobPositionDataTable is not an array. It is a table and you want the first row of the table JobPositionDataTable.Rows[0] – jdweng Dec 05 '18 at 20:29
  • @jdweng I'm guessing here, but since this is a typed designer, I don't think the Rows collection is necessary. It's been over 10 years since I had to play with typed sets though. – LarsTech Dec 05 '18 at 20:33
  • With both of these suggestions, I get an error message "An object reference is required for the non-static field, method or property" – Tullocco Dec 05 '18 at 20:42

2 Answers2

0

Youo should not put "DataTable" to the table name, I suppose:

string employeeName = _SOI_MasterDatabaseDataSet.JobPosition[0].EmployeeName;
Belurd
  • 772
  • 1
  • 13
  • 31
0

Looking at more Microsoft documentation, I found out I had to initialize the dataSet and dataTable and initialize a tableAdapter to fill the dataTable:

_SOI_MasterDatabaseDataSet SOI_MasterDatabaseDataSet = new _SOI_MasterDatabaseDataSet();

SOI_MasterDatabaseDataSet.JobPositionRow newJobPosition = SOI_MasterDatabaseDataSet.JobPosition.NewJobPositionRow();

_SOI_MasterDatabaseDataSetTableAdapters.JobPositionTableAdapter jobPositionTableAdapter = new _SOI_MasterDatabaseDataSetTableAdapters.JobPositionTableAdapter();

jobPositionTableAdapter.Fill(SOI_MasterDatabaseDataSet.JobPosition);

string positionTitle = SOI_MasterDatabaseDataSet.JobPosition[0].PositionTitle;
string employeeName = SOI_MasterDatabaseDataSet.JobPosition[0].EmployeeName;

Here are the additional sources I used: Edit data in datasets, Fill datasets by using TableAdapters

Tullocco
  • 11
  • 5