我想使用组合框中的一些文本过滤我的图表到我的sql中,然后我的sql将成为我的图表的数据源...但我很难用这个(我是图表新手)
到目前为止,这就是我所做的:
Dim rdr As OleDbDataReader
Dim CN1 As New OleDbConnection(cs)
CN1.Open()
adp = New OleDbDataAdapter()
adp.SelectCommand = New OleDbCommand("SELECT (ItemName) AS [Item Name], (ItemSize) AS [Item Size], (ConsumedDate) AS [Date], (ConsumedQuantity) AS [Quantity] from ConsumedItems where ItemName = '" & cbxItem.Text & _
"' AND ItemSize = '" & cbxSize.Text & "'", CN1)
'chrConsumption.Series("ActualConsumption").Points.AddXY(rdr.GetInt16("ConsumedQuantity"), rdr.GetString("ItemName"))
chrConsumption.Series("ActualConsumption").XValueMember = "ConsumedItems.ConsumedDate"
chrConsumption.Series("ActualConsumption").YValueMembers = "ConsumedItems.ConsumedQuantity"
上面的代码是我的第一次尝试无法正常工作......下面的代码正常工作,但x轴没有显示日期为月份
Try
Dim CN1 As New OleDbConnection(cs)
CN1.Open()
adp = New OleDbDataAdapter()
adp.SelectCommand = New OleDbCommand("SELECT (ConsumedDate) AS [Date], (ConsumedQuantity) AS [Quantity] from ConsumedItems where ItemName = '" & cbxItem.Text & _
"' AND ItemSize = '" & cbxSize.Text & "' AND ConsumedDate BETWEEN #" & dtpDateFrom.Value & "# AND #" & dtpDateTo.Value & "#", CN1)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
chrConsumption.Series("ActualConsumption").XValueMember = "Date"
chrConsumption.Series("ActualConsumption").YValueMembers = "Quantity"
chrConsumption.DataSource = dtable
chrConsumption.DataBind()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try