我正在编写一个追踪某些股票的小应用程序,我有一个包含股票数据的数据库,并希望将其输出到 WPF 数据网格中,但我遇到了以下错误:
无法将类型为“System.Single”的对象强制转换为类型“System.Double”
请原谅我的糟糕的编码技能,因为我已经几年没做过这个了。我查看了内部异常,但它只是显示 null。
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
using (AppDbContext db = new AppDbContext())
{
StockGrid.ItemsSource = db.LowFloatStocks.ToList();
}
}
}
}
Stock.cs
#region Day 1 Open Variabes
private int stockId;
private string stockTicker;
private double openingPrice;
private double spike;
private double high;
private double low;
private double closingPrice;
private double gainPercent;
private double gapPercent;
private double highPercent;
private double lowPercent;
private double closePercent;
private string greenToRed;
private string redToGreen;
private string closeLessEqualToOpen;
private string closeRed;
private double closeVHigh;
private double closeVOpen;
private string catalyst;
private double stockFloat;
private string dilution;
#endregion
#region Day 2 Open Variables
private double day2Open;
//private decimal day2Spike;
private double day2High;
private double day2Low;
private double day2Close;
private double day2gapPercent;
private double day2highPercent;
private double day2lowPercent;
private double day2ClosePercent;
private string day2GapUp;
private string day2GapDown;
private string day2GreenRed;
private string day2RedGreen;
private string day2CloseLessEqualOpen;
private string day2CloseRed;
private double day2CloseVHigh;
private double day2ClosevOpen;
SQL
CREATE TABLE [dbo].[LowFloatStocks] (
[Id] INT NOT NULL,
[Date] DATE NOT NULL,
[Ticker] NCHAR (10) NOT NULL,
[ClosingPrice] REAL NOT NULL,
[OpeningPrice] REAL NOT NULL,
[GainPercent] AS (round(([High]-[OpeningPrice])/[OpeningPrice],(4))*(100.0)) PERSISTED NOT NULL,
[GapPercent] AS (round(([OpeningPrice]-[ClosingPrice])/[ClosingPrice],(4))*(100.0)) PERSISTED NOT NULL,
[Spike] REAL NOT NULL,
[1stSpike%] AS (round(([Spike]-[OpeningPrice])/[OpeningPrice],(4))*(100.0)) PERSISTED NOT NULL,
[High] REAL NOT NULL,
[HighPercent] AS (round(([High]-[ClosingPrice])/[ClosingPrice],(4))*(100.0)) PERSISTED NOT NULL,
[Low] REAL NOT NULL,
[LowPercent] AS (round(([Low]-[ClosingPrice])/[ClosingPrice],(4))*(100.0)) PERSISTED NOT NULL,
[1stClose] REAL NOT NULL,
[ClosePercent] AS (round(([1stClose]-[ClosingPrice])/[ClosingPrice],(4))*(100.0)) PERSISTED NOT NULL,
[greenToRed] NCHAR (3) NOT NULL,
[redToGreen] NCHAR (3) NOT NULL,
[CloseLessEqualToOpen] NCHAR (3) NOT NULL,
[CloseRed] NCHAR (3) NOT NULL,
[ClosevHigh] AS (round(([High]-[1stClose])/[1stClose],(4))*(100)) PERSISTED NOT NULL,
[ClosevOpen] AS (round(([OpeningPrice]-[1stClose])/[OpeningPrice],(4))*(100.0)) PERSISTED NOT NULL,
[Catalyst] NVARCHAR (50) NOT NULL,
[Float] DECIMAL (18) NOT NULL,
[Dilution] NCHAR (3) NOT NULL,
[Day2Open] REAL NOT NULL,
[day2gapPercent] AS (round(([Day2Open]-[1stClose])/[1stClose],(4))*(100.0)) PERSISTED NOT NULL,
[Day2High] REAL NOT NULL,
[day2HighPercent] AS (round(([Day2High]-[1stClose])/[1stClose],(4))*(100)) PERSISTED NOT NULL,
[Day2Low] REAL NOT NULL,
[Day2LowPercent] AS (round(([Day2Low]-[1stClose])/[1stClose],(4))*(100.0)) PERSISTED NOT NULL,
[Day2Close] REAL NOT NULL,
[Day2ClosePercent] AS (round(([Day2Close]-[1stClose])/[1stClose],(4))*(100.0)) PERSISTED NOT NULL,
[Day2GapUp] NCHAR (3) NOT NULL,
[Day2GapDown] NCHAR (3) NOT NULL,
[Day2GreenToRed] NCHAR (3) NOT NULL,
[Day2RedToGreen] NCHAR (3) NOT NULL,
[Day2CloseLessEqualToOpen] NCHAR (3) NOT NULL,
[Day2CloseRed] NCHAR (3) NOT NULL,
[Day2ClosevHigh] AS (round(([Day2Open]-[Day2High])/[Day2Open],(4))*(100.0)) PERSISTED NOT NULL,
[Day2ClosevOpen] AS (round(([Day2Open]-[Day2Close])/[Day2Open],(4))*(100.0)) PERSISTED NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);