gpt4 book ai didi

c# - 无法将类型为 'System.Single' 的对象转换为类型 'System.Double'。”

转载 作者:行者123 更新时间:2023-12-05 01:35:18 24 4
gpt4 key购买 nike

我目前正在编写一个跟踪某些股票的小应用程序,我有一个包含股票数据的数据库并想将其输出到 WPF 数据网格,但我收到以下错误:

Unable to cast object of type 'System.Single' to type 'System.Double'

请原谅我糟糕的编码技巧,因为我已经有几年没有这样做了,我查看了内部异常,但它只是说 null。

    public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
using (AppDbContext db = new AppDbContext())
{
StockGrid.ItemsSource = db.LowFloatStocks.ToList();
}
}
}
}

股票.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)
);

最佳答案

要么将所有 DBTypes 从 REAL 更改为 FLOAT,要么将 C# 类型从 double 更改为 float

DBType REAL is float in C#
DBType FLOAT is double in C#

关于c# - 无法将类型为 'System.Single' 的对象转换为类型 'System.Double'。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63054970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com