我試圖將結果返回給圖表並繪製圖表。我返回的數據庫數據是日期時間和浮點數,因爲它們都是對象,所以應該可以工作。我得到的錯誤是存儲過程中的points.addxy
不能從
string
轉換爲int
在AddXY
方法兩個參數。
string dateSelected = monthCalendarAdv1.Value.ToShortDateString();
dataConnection.Open();
SqlCommand dataCommand4 = new SqlCommand("SpTimeSeriesTotalParity", dataConnection);
dataCommand4.Connection = dataConnection;
dataCommand4.CommandType = CommandType.StoredProcedure;
dataCommand4.Parameters.Add(new SqlParameter("@ValDate", dateSelected));
dataCommand4.Parameters.Add(new SqlParameter("@Acct", cmbSelectAccno.Text));
下面的代碼是相似的,併爲第一個參數工作沒有任何問題。
this.chart1.Series["$Parity"].Points.AddXY("Item1",1);
this.chart1.Series["$Parity"].Points.AddXY("Item2", 2);
this.chart1.Series["$Parity"].Points.AddXY("Item3", 3);
this.chart1.Series["$Parity"].Points.AddXY("Item4", 4);
this.chart1.Series["$Parity"].Points.AddXY("Item5", 5);
try
{
dataConnection.Open();
using (SqlDataReader myReader = dataCommand4.ExecuteReader())
// myReader = dataConnection.ExecuteReader();
while (myReader.Read())
{
this.chart1.Series["$Parity"].Points.AddXY
(myReader.GetDateTime("ValuationDate"), myReader.GetDouble("SumParity"));
}
}
我編輯了自己的冠軍。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –