I'm new to MS Chart control. I want to display sql conditional result in chart control. This is my codes
Dim strQry As String = "SELECT format(sDate, 'MMMM-YYYY') AS [Month], iCode as [Item], Sum(iQty) AS [Total Qty] FROM Sales WHERE iCode ='DJ100106' OR iCode='DJ100107' GROUP BY format(sDate, 'MMMM-YYYY'), icode ORDER BY cDate(format(sDate, 'MMMM-YYYY'))"
Dim dt As New DataTable
Dim da As New OleDbDataAdapter(sqlQry, Conn)
da.Fill(dt)
Chart1.Series(0).Color = Color.YellowGreen
Chart1.Series(0).XValueMember = "Month"
Chart1.Series(0).YValueMembers = "Total Qty"
Chart1.Series(0).IsValueShownAsLabel = True
Chart1.DataSource = dt
For one condition in WHERE clause, chart control displays the bars correctly. If I add more condition such as "OR iCode = 'DJ100107'", chart control displays inappropriate bars and values in X axis.
I want to compare these two items (DJ100106 and DJ100107) sold in every month in chart. Grid control displays the exact result what I want. But the chart control doesn't. (As shown in the attached image). I am using VB.Net 2012, MS Access Database 2007
Can anyone help me how to solve this?
Thank you
Related
I have 3 compobboxes I have created an import code from a SQL table
The problem when I choose a value from the first compbox
the values of other compbox is changed to be like my choice
I made a separate code for each compbox
But I find it impractical because my project has 90 compoboxes
It needs time to run
Is there a more practical solution?
this is my code...
Dim com As New SqlCommand("select Distinct Name1 from TB_dr", Con)
Dim RD As SqlDataReader = com.ExecuteReader
Dim DT As DataTable = New DataTable
DT.Load(RD)
ComboBox1.DisplayMember = "Name1"
ComboBox1.DataSource = DT
ComboBox2.DisplayMember = "Name1"
ComboBox2.DataSource = DT
ComboBox3.DisplayMember = "Name1"
ComboBox3.DataSource = DT
Only populate a combobox on its dropdown event.
That will make your app faster cause your client may not use them all and if he uses one combobox he would populate a small amount of data only.
And no data is populated on load.
As i look at what you are trying to do which is same data for all comboboxes, you can simply put all your comboboxes in a group, and go through your group to populate them all at once.
like for each cb in that group, cb.datasource = dt.
call the datatable once
I have a form that should display a slope value for different transects on a plot, all tied to a single event, using different text boxes.
For example:
There is a monitoring event record. The StandTransectSlope table has 3 rows for one EventID: slope for the UP (upper, ID=1) transect, slope for the BL (bottom left, ID=2) transect, slope for the BR (bottom right, ID=3) transect.
I have 3 text boxes: one box to display the slope value for each of the transects (1-3).
I did have a crosstab query behind this form so that I could, easily, assign those different slope values from each row by the transect name. But then I found out the crosstab query is not updateable. Users need to be able to add new data, as well as view data already entered. How can I code to allow this?
Currently, I have the following code on the Form_Load event (I'll have to also add code for AfterUpdate for the form):
Private Sub Form_Load()
Dim ID As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT * FROM xrefCOMN_StandEventTransectSlope WHERE EventID =" & Me.EventID
Set rs = db.OpenRecordset(strSQL)
'Set values for slope text boxes by ID
Select Case ID
Case 1
Me.txtSlopeUP.Value = DLookup("Slope", "xrefCOMN_StandEventTransectSlope", "EventID=" & Me.EventID)
Case 2
Me.txtSlopeBR.Value = DLookup("Slope", "xrefCOMN_StandEventTransectSlope", "EventID=" & Me.EventID)
Case 3
Me.txtSlopeBL.Value = DLookup("Slope", "xrefCOMN_StandEventTransectSlope", "EventID=" & Me.EventID)
Case Else
'Nothing
End Select
End Sub
question may need rewording, but here is the issue, and code I am using is posted below
some background so as to understand I have a datatable bound to a datagridview with a column name column names in the code I will only show a portion of column names to save space, this section works but its needed to show issues
DataGridView3.DataSource = fieldDT
DataGridView3.AutoGenerateColumns = True
fieldDT.Columns.Add("Column Name", System.Type.GetType("System.String"))
DataGridView3.Columns(0).Width = 123
fieldDT.Columns.Add("Field", System.Type.GetType("System.String"))
DataGridView3.Columns(1).Width = 86
'columns 2 through 12 are here
fieldDT.Columns.Add("Format", System.Type.GetType("System.String"))
DataGridView3.Columns(13).Width = 45
fieldDT.Columns.Add(" ", System.Type.GetType("System.String"))
DataGridView3.Columns(14).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
I also have a combobox that I want populated with the column name in the above datatable code to bind shown next
ComboBox10.DataSource = fieldDT
ComboBox10.DisplayMember = "Column Name"
ComboBox10.ValueMember = "Column Name"
the combobox populates correctly with all the columnnames in the datatable
now is where the issue that I need a way to fix arises,
if I select a row in the datagridview it is changing the displayed value in the combobox, and if I select a different value in the combobox it changes the selected row in the datagridview my feeling this is by default design but hoping it can be changed
although the combobox needs that column list and needs to be upto date if someone adds another row to the datagridview I don't want them to bind in the way they change each other.
the combo box is used for another purpose that it needs to select one of the available column names
I made the suggested change and now works as intended
thanks
Dim DV_fields As DataView = fieldDT.DefaultView
ComboBox10.DataSource = DV_fields
ComboBox10.DisplayMember = "Column Name"
ComboBox10.ValueMember = "Column Name"
ComboBox10.Text = ""
Firstly I used the following to populate the DataGridView:
dta = New OleDbDataAdapter("Select * From [" & ActName & "$B6:E" & LastEntryRow & "]", cn)
dts = New DataSet
dta.Fill(dts, "Detailtable")
DataGridView1.DataSource = dts
DataGridView1.DataMember = "Detailtable"
I then formatted the DataGridView which included the following code:
Dim currencyCellStyle As New DataGridViewCellStyle
currencyCellStyle.Format = "C2"
With Me.DataGridView
.Columns(1).DefaultCellStyle = currencyCellStyle
.Columns(2).DefaultCellStyle = currencyCellStyle
End with
This worked well. Columns displayed their values as $1234.00.
When new values were added to the columns they immediately displayed as $1234.00. (working so far)
If a column did not have any values when the dataset was made, no values showed in the datagridview for that column. (no problem so far)
However, all new values added to the blank column display as 1234.00. Not $1234.00.
I have tried refreshing the DataGridView
I have re-formatted the DataGridView after the change to the cell.
It still displays as 1234.00.
If I save the changes, recreate the DataSet and repopulate the DataGridView all is OK.
I need the DataGridView to reflect the correct format ($1234.00) when new values are added directly to the column?????
If you use this line
DataGridView1.Columns(1).DefaultCellStyle.Format = "C2"
it must be work but if your database column format is not Decimal (but TEXT), this type of format it'll never works.
I created a avery 5160 report in Crystal Reports through the wizard. When I pass my values to Crystal it is only showing 1 label in the report viewer.
Do I have to tell Crystal I want 30 of these to print on one page in code?
Is there a way to check my settings after the wizard completes?
Here is my report code:
Dim report As New Avery5160()
Dim ds As DataSet = New DataSet
Dim dt = New CrystalDS.DataTable1DataTable()
ds.Tables.Add(dt)
report.SetDataSource(ds)
dt.Rows.Add(bmpBytes)
report.SetParameterValue(0, Desc)
report.SetParameterValue(1, WriteUPC)
CrystalReportViewer1.ReportSource = report
CrystalReportViewer1.Refresh()
I was able to figure it out by creating a loop to add the item 30 times to the report.
For i = 0 To 29
dt.Rows.Add(bmpBytes)
report.SetParameterValue(0, Desc)
report.SetParameterValue(1, WriteUPC)
Next