A
Andreas Oswald
Hi there,
I have a problem with accessing decimal values in a table like the
following one:
create table sap_BelegZeile(
....
DEC_STEUER decimal(5,2),
DEC_BETRAG decimal(14,2),
....
);
str_SQL = "select DEC_STEUER from sap_Belegzeile";
OleDbCommand qry_BelegZeilen = new OleDbCommand(str_SQL,
con_DatenbankVerbindung);
OleDbDataReader rst_BelegZeilen = qry_BelegZeilen.ExecuteReader();
//further analysis of the resulting OleDbDataReader
DataTable dt = rst_BelegZeilen.GetSchemaTable();
DataView dv = dt.DefaultView;
dv.RowFilter = "ColumnName='dec_betrag'";
DataRowView dr = dv[0];
Console.WriteLine(dr["ColumnName"]);
Console.WriteLine(dr["ColumnSize"]);
Console.WriteLine(dr["NumericPrecision"]);
Console.WriteLine(dr["NumericScale"]);
Console.WriteLine(dr["DataType"].ToString());
while (rst_BelegZeilen.Read())
{
Console.WriteLine("Row has {0} Columns.",
rst_BelegZeilen.FieldCount);
Console.WriteLine("TypeName: {0}",
rst_BelegZeilen.GetDataTypeName(0));
Console.WriteLine("IsDbNull: {0}", rst_BelegZeilen.IsDbNull(0));
//The following line 822 throws an System.InvalidOperationException
Decimal dec_steuer = rst_Belege.GetDecimal(0);
Console.WriteLine(dec_steuer);
}
For str_SQL = "select DEC_STEUER from sap_Belegzeile"; the above
snippet outputs
DEC_STEUER
19
5
2
System.Decimal
Row has 1 Columns.
TypeName: DBTYPE_NUMERIC
IsDbNull: False
Unbehandelte Ausnahme: System.InvalidOperationException: Keine Daten
für die Zeile/Spalte.
at System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal)
at System.Data.OleDb.OleDbDataReader.GetDecimal(Int32 ordinal)
at ApertumFileExport.FileExport.Main(String[] args) in
d:\oswald\experimente\apertumfileexport\class1.cs:line 822
and for str_SQL = "select DEC_BETRAG from sap_belegzeile"; it outputs
select DEC_BETRAG from sap_
DEC_BETRAG
19
14
2
System.Decimal
Row has 1 Columns.
TypeName: DBTYPE_NUMERIC
IsDbNull: False
Unbehandelte Ausnahme: System.InvalidOperationException: Keine Daten
für die Zeile/Spalte.
at System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal)
at System.Data.OleDb.OleDbDataReader.GetDecimal(Int32 ordinal)
at ApertumFileExport.FileExport.Main(String[] args) in
d:\oswald\experimente\apertumfileexport\class1.cs:line 822
What's going wrong there? If I do the same query from SQL Query
Analyzer, I get results like the following:
dec_betrag
----------------
19795.05
19795.05
(2 row(s) affected)
I also tried using SqlCommand and OdbcCommand instead of OleDbCommand,
results stay the same, I can't get those values.
I have used very similar code on very similar tables successfully, so I
really don't understand the exception.
For the not German-Speaking "Keine Daten für die Zeile/Spalte." means
something like "No data for Row/Column." and "Unbehandelte Ausnahme:"
is "Unhandled Exception:"
Any hints?
Thanks in advance for your help
Andreas
I have a problem with accessing decimal values in a table like the
following one:
create table sap_BelegZeile(
....
DEC_STEUER decimal(5,2),
DEC_BETRAG decimal(14,2),
....
);
str_SQL = "select DEC_STEUER from sap_Belegzeile";
OleDbCommand qry_BelegZeilen = new OleDbCommand(str_SQL,
con_DatenbankVerbindung);
OleDbDataReader rst_BelegZeilen = qry_BelegZeilen.ExecuteReader();
//further analysis of the resulting OleDbDataReader
DataTable dt = rst_BelegZeilen.GetSchemaTable();
DataView dv = dt.DefaultView;
dv.RowFilter = "ColumnName='dec_betrag'";
DataRowView dr = dv[0];
Console.WriteLine(dr["ColumnName"]);
Console.WriteLine(dr["ColumnSize"]);
Console.WriteLine(dr["NumericPrecision"]);
Console.WriteLine(dr["NumericScale"]);
Console.WriteLine(dr["DataType"].ToString());
while (rst_BelegZeilen.Read())
{
Console.WriteLine("Row has {0} Columns.",
rst_BelegZeilen.FieldCount);
Console.WriteLine("TypeName: {0}",
rst_BelegZeilen.GetDataTypeName(0));
Console.WriteLine("IsDbNull: {0}", rst_BelegZeilen.IsDbNull(0));
//The following line 822 throws an System.InvalidOperationException
Decimal dec_steuer = rst_Belege.GetDecimal(0);
Console.WriteLine(dec_steuer);
}
For str_SQL = "select DEC_STEUER from sap_Belegzeile"; the above
snippet outputs
DEC_STEUER
19
5
2
System.Decimal
Row has 1 Columns.
TypeName: DBTYPE_NUMERIC
IsDbNull: False
Unbehandelte Ausnahme: System.InvalidOperationException: Keine Daten
für die Zeile/Spalte.
at System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal)
at System.Data.OleDb.OleDbDataReader.GetDecimal(Int32 ordinal)
at ApertumFileExport.FileExport.Main(String[] args) in
d:\oswald\experimente\apertumfileexport\class1.cs:line 822
and for str_SQL = "select DEC_BETRAG from sap_belegzeile"; it outputs
select DEC_BETRAG from sap_
DEC_BETRAG
19
14
2
System.Decimal
Row has 1 Columns.
TypeName: DBTYPE_NUMERIC
IsDbNull: False
Unbehandelte Ausnahme: System.InvalidOperationException: Keine Daten
für die Zeile/Spalte.
at System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal)
at System.Data.OleDb.OleDbDataReader.GetDecimal(Int32 ordinal)
at ApertumFileExport.FileExport.Main(String[] args) in
d:\oswald\experimente\apertumfileexport\class1.cs:line 822
What's going wrong there? If I do the same query from SQL Query
Analyzer, I get results like the following:
dec_betrag
----------------
19795.05
19795.05
(2 row(s) affected)
I also tried using SqlCommand and OdbcCommand instead of OleDbCommand,
results stay the same, I can't get those values.
I have used very similar code on very similar tables successfully, so I
really don't understand the exception.
For the not German-Speaking "Keine Daten für die Zeile/Spalte." means
something like "No data for Row/Column." and "Unbehandelte Ausnahme:"
is "Unhandled Exception:"
Any hints?
Thanks in advance for your help
Andreas