更新时间:2023-11-17 14:02:28
您可以在CommandText中进行操作,即
You can do it in your CommandText i.e
SELECT Price, Date, High, Low, (High - Low) AS Difference From myReport
那么您可以像这样从阅读器中读取行
then you can read the rows from your reader like this
li.SubItems.Add(reader["Price"].ToString();
li.SubItems.Add(reader["Date"].ToString();
li.SubItems.Add(reader["High"].ToString();
li.SubItems.Add(reader["Low"].ToString();
li.SubItems.Add(reader["Difference"].ToString();
尽管我认为这是做事的错误方法.如果您是我,我不会将数据作为字符串存储在数据库中,而是使用适当的数据类型并检索这样的数据
although I think this is the wrong way to go about things. If I were you I would not store my data in the database as strings, instead I would use the appropriate data type and retrieve the data like this
li.SubItems.Add(reader.GetDecimal(0);
li.SubItems.Add(reader.GetDate(1); etc
很明显,这是在您检查阅读器没有返回任何Null值之后.
希望这对您有帮助
This is obviously after you have checked that the reader is not returning any Null values.
Hope this helps
您必须获取两个值并将其相减.
例如,如果您的值的类型为int
:
You have to get the two values and subtract those.
For example, if your values are of typeint
:
int high = ( int ) reader[ "High" ];
int low = ( int ) reader[ "Low" ];
int range = high - low;
li.SubItems.Add( range.ToString() );
尼克
Nick