I'm filling datatables using queries to a database. I'm storing all my queries in a static class, then in a different class I'm sorting/filtering these tables. I ran into an issue pulling the generated datatable into that other class where I'm doing all the sorting, any calculations, etc. involving the data. How do I pull the generated tables into a button_click method in C#?
One of my queries:
string HeaderString =
@" SELECT
ID,
model,
series,
short_name,
published,
VALID_DTTM
FROM
HEAD_TABLE;
DataTable Headerdtbl = null;
if(IsConnected()) {
try {
string HeaderQuery = string.Format(HeaderString, Model);
OracleDataAdapter HeaderdataAdapter = new OracleDataAdapter(HeaderQuery, A.ServerConnection.oracleConnection);
Headerdtbl = new DataTable("HEAD");
HeaderdataAdapter.Fill(Headerdtbl);
}
catch(Exception ex) {
using ExceptionDialog exDialog = new(ex);
exDialog.ShowDialog();
Headerdtbl = null;
}
}
return Headerdtbl;
The code I get errors with:
(This is in a different class.)
private void PopulateButton_Click(object sender, EventArgs e)
{
// Sort data
DataView HeaderView = new(Headerdtbl);
HeaderView.Sort = "PUBLISHED ASC";
HeaderView = new DataView(Headerdtbl);
HeaderView.Sort = "SHORT_NAME ASC";
HeaderView = new DataView(Headerdtbl);
HeaderView.Sort = "MODEL ASC";
Headerdtbl = HeaderView.ToTable();
Error I get: CS0103 The name 'identifier' does not exist in the current context.
I know the most obvious solution is to just put the query in with the button click code but unfortunately I can't move the query out of the class its in as thats the designated location for querying from the database. I need a way to pull the established table into my button click method. Any good ways to do this?