- Joined
- Apr 1, 2006
- Messages
- 1
- Reaction score
- 0
Nested queries to populate a DataSet using OdbcDataAdapter
The class listed below uses a CSV file and OdbcDataAdapter object to populate a DataSet using a nested query BUT I keep getting an Access Violation exception.
Are nested queries in the SelectCommand() method of the OdbcDataAdapter object not valid? I essentially need to execute this query to populate the DataSet:
SELECT Value,Pressure,Temperature
FROM DewPointValues
WHERE Pressure IN ((SELECT MAX(Pressure)
FROM DewPointValues
WHERE Pressure <= 9.2),
(SELECT MIN(Pressure)
FROM DewPointValues
WHERE Pressure >= 9.2))
AND Temperature IN ((SELECT MAX(Temperature)
FROM DewPointValues
WHERE Temperature <= 92.3),
(SELECT MIN(Temperature)
FROM DewPointValues
WHERE Temperature >= 92.3))
public class DewPoint
{
protected DataSet DewPointValues = new DataSet("DewPointValues");
protected OdbcConnection DewPointValuesConn;
public DewPoint()
{
LoadDewPointValuesFile();
}
publicdouble GetH2OContentValue(double pressure, double temperature)
{
double lookupValue = 0.0;
string query = "SELECT * FROM DewPointValues.csv WHERE Pressure IN ((SELECT MAX(Pressure) FROM DewPointValues.csv WHERE Pressure <= " + pressure + "), (SELECT MIN(Pressure) FROM DewPointValues.csv WHERE Pressure >= " + pressure + "))";
OdbcDataAdapter da = new OdbcDataAdapter();
da.SelectCommand = new OdbcCommand(query, DewPointValuesConn);
da.Fill(DewPointValues, "Values");
DataRow[] foundRows = DewPointValues.Tables["Values"].Select();
if (foundRows.GetUpperBound(0) >= 0)
{
foreach (DataRow row in foundRows)
{
lookupValue += Convert.ToDouble(row["Value"]);
}
}
return lookupValue;
}
privatevoid LoadDewPointValuesFile()
{
System.Reflection.Assembly myAssembly = this.GetType().Assembly;
string path = myAssembly.Location;
path = path.Substring(0, path.LastIndexOf("\\") + 1);
// Connection string for a Text File
string ConnectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" + path;
DewPointValuesConn = new OdbcConnection(ConnectionString);
DewPointValuesConn.Open();
}
Any help would be appreciated!!!
The class listed below uses a CSV file and OdbcDataAdapter object to populate a DataSet using a nested query BUT I keep getting an Access Violation exception.
Are nested queries in the SelectCommand() method of the OdbcDataAdapter object not valid? I essentially need to execute this query to populate the DataSet:
SELECT Value,Pressure,Temperature
FROM DewPointValues
WHERE Pressure IN ((SELECT MAX(Pressure)
FROM DewPointValues
WHERE Pressure <= 9.2),
(SELECT MIN(Pressure)
FROM DewPointValues
WHERE Pressure >= 9.2))
AND Temperature IN ((SELECT MAX(Temperature)
FROM DewPointValues
WHERE Temperature <= 92.3),
(SELECT MIN(Temperature)
FROM DewPointValues
WHERE Temperature >= 92.3))
public class DewPoint
{
protected DataSet DewPointValues = new DataSet("DewPointValues");
protected OdbcConnection DewPointValuesConn;
public DewPoint()
{
LoadDewPointValuesFile();
}
publicdouble GetH2OContentValue(double pressure, double temperature)
{
double lookupValue = 0.0;
string query = "SELECT * FROM DewPointValues.csv WHERE Pressure IN ((SELECT MAX(Pressure) FROM DewPointValues.csv WHERE Pressure <= " + pressure + "), (SELECT MIN(Pressure) FROM DewPointValues.csv WHERE Pressure >= " + pressure + "))";
OdbcDataAdapter da = new OdbcDataAdapter();
da.SelectCommand = new OdbcCommand(query, DewPointValuesConn);
da.Fill(DewPointValues, "Values");
DataRow[] foundRows = DewPointValues.Tables["Values"].Select();
if (foundRows.GetUpperBound(0) >= 0)
{
foreach (DataRow row in foundRows)
{
lookupValue += Convert.ToDouble(row["Value"]);
}
}
return lookupValue;
}
privatevoid LoadDewPointValuesFile()
{
System.Reflection.Assembly myAssembly = this.GetType().Assembly;
string path = myAssembly.Location;
path = path.Substring(0, path.LastIndexOf("\\") + 1);
// Connection string for a Text File
string ConnectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" + path;
DewPointValuesConn = new OdbcConnection(ConnectionString);
DewPointValuesConn.Open();
}
Any help would be appreciated!!!
Last edited: