I have a sub called addchartPrevious24()
This sub is being called on the initial load and when the user calls for a refresh. The job of this sub is to go out to an access database query the information. Populate into a dataset. Then create a chart and chart area. The dataset is then set as the datasource of the chart. My issue is if i reexecute the sub it does not update the chart with the new data although the dataset does get updated.
Public Sub addchartPrevious24()
Dim Connection As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\manage.mdb;Jet OLEDB:Database Password=password")
Dim da1 As New OleDb.OleDbDataAdapter
Dim ds1 As New DataSet()
Dim Command As New OleDb.OleDbCommand
Connection.Open()
da1.SelectCommand = New OleDb.OleDbCommand("SELECT General_Counters_Table.product_id, Sum(General_Counters_Table.ulboardcyclecount) AS SumOfulboardcyclecount, ltrim(STR(Month(General_Counters_Table.Date_Time)))+ '/'+Ltrim(STR(Day(General_Counters_Table.Date_Time))) + '/'+ltrim(STR(Year(General_Counters_Table.Date_Time))) + ' hour ' +Ltrim(STR(Hour(General_Counters_Table.Date_Time))) as DATEConverted FROM General_Counters_Table where Date_Time >=(NOW()-1) and Date_Time <= (NOW()) GROUP BY General_Counters_Table.product_id, Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time) ORDER BY Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time)", Connection)
da1.Fill(ds1, "Throughput")
Connection.Close()
'Defines Chart and Chart Area
Dim chart1 = New Chart()
Dim chartarea1 As ChartArea = New ChartArea()
TabPage2.Controls.Add(chart1)
chartarea1.Name = "ChartArea1"
chart1.ChartAreas.Add(chartarea1)
Chart1.Location = New System.Drawing.Point(10, 10)
chart1.Name = "Chart1"
Chart1.Size = New System.Drawing.Size(800, 400)
chart1.TabIndex = 0
chart1.Text = "Chart1"
chartarea1.AxisX.LabelStyle.Angle = -60
chartarea1.AxisX.Interval = 1
chartarea1.AxisY.MajorGrid.Interval = 5
chartarea1.BackColor = Color.Azure
chartarea1.ShadowColor = Color.Red
chartarea1.Area3DStyle.Enable3D = True
chartarea1.AxisX.MajorGrid.Enabled = False
chartarea1.AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Italic)
'Legend
Dim legend1 As Legend = New Legend()
legend1.Name = "Legend1"
chart1.Legends.Add(legend1)
'Series
Dim series1 As Series = New Series()
series1.ChartType = SeriesChartType.StackedColumn
series1.ChartArea = "ChartArea1"
series1.Legend = "Legend1"
series1.Name = "Throughput"
chart1.Series.Add(series1)
chart1.Series("Throughput").XValueMember = "DateConverted"
chart1.Series("Throughput").YValueMembers = "sumofulboardcyclecount"
chart1.Series("Throughput").IsValueShownAsLabel = True 'shows label on datapoint
chart1.DataSource = ds1.Tables("Throughput")
chart1.Update()
chart1.DataBind()
End Sub
I had the same problem, a resolution is presented for "This Question"
Try clearing your data points using:
Chart.Series.Points.Clear()
and then adding them again.
Related
newbie here; Im trying to migrate my VB program to run in Tabs. so far I have been experimenting with creating Tabs at runtime with added controls. I figured out that I can create tabs and add controls at either FormLoad() or by an execute Button. However, I can not access those controls once the Tab is created. I can not get any info from a combo, text box either outside the created Tab. Here is a simple program that I manage to put together:
Public Class Form1
Inherits Form
Private tabControl1 As TabControl
Private tabPage1 As TabPage
Private tabPage2 As TabPage
Dim nm As String
Private Sub MyTabs()
Me.tabControl1 = New TabControl()
Me.tabPage1 = New TabPage()
Me.tabPage2 = New TabPage()
Dim txtBox1 As New Windows.Forms.TextBox With {.Parent = tabPage1}
Dim CalcButton As New Windows.Forms.Button With {.Parent = tabPage1}
CalcButton.Location = New Point(1572, 150)
CalcButton.Size = New Point(100, 50)
CalcButton.Text = "CALCULATE"
txtBox1.Location = New Point(1572, 258)
txtBox1.Size = New Point(70, 22)
txtBox1.Name = "Loc_num"
txtBox1.Text = "1"
nm = txtBox1.Text
Me.tabControl1.Controls.AddRange(New Control() {Me.tabPage1, Me.tabPage2})
Me.tabControl1.Padding = New Point(15, 10)
Me.tabControl1.Location = New Point(35, 25)
Me.tabControl1.Size = New Size(1800, 750)
' Selects tabPage1 using SelectedTab
Me.tabControl1.SelectedTab = tabPage1
Me.tabPage1.Text = "tabPage1"
Me.tabPage2.Text = "tabPage2"
Me.Size = New Size(2000, 900)
Me.Controls.AddRange(New Control() {Me.tabControl1})
AddHandler CalcButton.Click, AddressOf CalcButton_Click
End Sub
Private Sub CalcButton_Click()
Dim xx As Integer
Me.tabControl1.SelectedTab = tabPage1
xx = Convert.ToInt32(nm) ' IT KEEPS SHOWING A 1, EVENTHOU I CHANGED IT TO 4 WHEN FORM LOADS
MessageBox.Show(nm)
End Sub
Public Sub New()
MyTabs()
End Sub
Public Sub Main()
Application.Run(New Form1())
End Sub
End Class
Im not sure if its possible to continue of this path
Thanks for any help or comment
In my datagridview, I just want to show other fields such as ID,LastName,FirstName, and MiddleName and i dont want to show any fields but i want it to retrieve even it's hidden. But when i specify what i just want to show in my datagridview it causes runtime error.
this is my code to load the datagridview.
MysqlConn.Open()
Dim Query As String
Query = "select ID,LastName,FirstName,MiddleName from god.precord"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
then this is my code for retrieve data into textboxes
Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
txtid.Text = row.Cells("ID").Value.ToString
txtlastname.Text = row.Cells("LastName").Value.ToString
txtfirstname.Text = row.Cells("FirstName").Value.ToString
txtmiddlename.Text = row.Cells("MiddleName").Value.ToString
txtaddress.Text = row.Cells("Address").Value.ToString
txtcontactno.Text = row.Cells("ContactNo").Value.ToString
txtgender.Text = row.Cells("Gender").Value.ToString
dtpbirthdate.Text = row.Cells("Birthdate").Value.ToString
txtage.Text = row.Cells("Age").Value.ToString
End If
End Sub
runtime error
please help me this is for my thesis
thankyou in advance <3
You have to add hidden column into the select query to retreive the data.
Hide the column from the DataGridView instead.
try
MysqlConn.Open()
Dim Query As String
Query = "select ID,LastName,FirstName,MiddleName,Address from god.precord"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
DataGridView1.Columns("Address").Visible = false
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
I have created a form that has a subform attached. I have a button that runs a query to delete the record but first I want to copy the data from including all subform information if available to a table. I have used the following code but nothing happens. please! what am I have missing?
Private Sub Command63_Click()
Dim db As Database, delfile As Recordset, Criteria As String
Set db = CurrentDb
Set delfile = db.OpenRecordset("DelFile", DB_OPEN_DYNASET)
'add data to deleted taxpayer file table
With delfile
.AddNew
!DeletedBy = (Forms!MainMenu!username)
!Branch = Me.Branch
!TaxType = Me.TaxType
!Volume = Me.Volume
!Keyedby = Me.Keyedby
!DateKeyed = Me.DateKeyed
!CreatedAt = Me.CreatedAt
!Comment = Me.Comment
End With
delfile.Close
db.Close
End Sub
Once you have set all of your field values you need to include a .update for the changes to take affect. Your new code would look like this.
Private Sub Command63_Click()
Dim db As Database, delfile As Recordset, Criteria As String
Set db = CurrentDb
Set delfile = db.OpenRecordset("DelFile", DB_OPEN_DYNASET)
'add data to deleted taxpayer file table
With delfile
.AddNew
!DeletedBy = (Forms!MainMenu!username)
!Branch = Me.Branch
!TaxType = Me.TaxType
!Volume = Me.Volume
!Keyedby = Me.Keyedby
!DateKeyed = Me.DateKeyed
!CreatedAt = Me.CreatedAt
!Comment = Me.Comment
.Update
End With
delfile.Close
db.Close
End Sub
I have the following code which lets me append a gridview and detailview as PDF file
But what I hope to achieve is not to download it but to attach it as email to send to the designated user. Is there any way I can modify the code so that I can send it as email and instead of download.
Dim strQuery As String = "SELECT * FROM [PointOrder] WHERE PointOrderId =" & Session("PointOrder")
Dim cmd As New SqlCommand(strQuery)
Dim dt As DataTable = GetData(cmd)
Dim DetailsView1 As New DetailsView()
DetailsView1.AllowPaging = False
DetailsView1.DataSource = dt
DetailsView1.DataBind()
Dim strQuery2 As String = "SELECT PointsOrderDetail.RedeemId, Redeem.RedeemName, Redeem.RedeemPoints, PointsOrderDetail.RedeemOrderQuantity, Redeem.RedeemPoints * PointsOrderDetail.RedeemOrderQuantity AS Total_Points FROM PointsOrderDetail INNER JOIN Redeem ON PointsOrderDetail.RedeemId = Redeem.RedeemId WHERE PointsOrderDetail.PointOrderId = " & Session("PointOrder")
Dim cmd2 As New SqlCommand(strQuery2)
Dim dt2 As DataTable = GetData(cmd2)
Dim GridView1 As New GridView()
GridView1.AllowPaging = False
GridView1.DataSource = dt2
GridView1.DataBind()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=" & Session("ID") & "-" & Session("PointOrder") & "-RedeemConfirm.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
DetailsView1.RenderControl(hw)
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
Private Function GetData(ByVal cmd As SqlCommand) As DataTable
Dim dt As New DataTable()
Dim strConnString As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("LegacySGConnectionString").ConnectionString()
Dim con As New SqlConnection(strConnString)
Dim sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
Try
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
Return dt
Catch ex As Exception
Throw ex
Finally
con.Close()
sda.Dispose()
con.Dispose()
End Try
End Function
Page1:
From Date: TXTBOX1 To Date: TXTBOX2
BTNSUBMIT-CLICK
{
server.transfer("page2.aspx");
}
Page 2:
if (PreviousPage != null)
{
TextBox txt1 = PreviousPage.FindControl("TXTBOX1") as TextBox;
TextBox txt2 = PreviousPage.FindControl("TXTBOX2") as TextBox;
if (txt1.Text.Length != 0 && txt2.Text.Length != 0)
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("MyReport.rpt");
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new
ParameterDiscreteValue();
crParameterDiscreteValue.Value = txt1.Text + txt2.Text;
crParameterFieldDefinitions =
cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition =
crParameterFieldDefinitions["MyParameter"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
CrystalReportViewer1.ReportSource = cryRpt;
}
}
Formula In Formula Editor:
{Command.Date} >= {?MyParameter} and {Command.Date} <= {?MyParameter}
It works fine If report is displayed for single date. Not for Date Range.
Any Suggestions? Where i am wrong in formula / code ???
You should pass the date fields as separate parameters, and reference them in your Formula Editor like this:
{Command.Date} >= {?ParamDateFrom} and {Command.Date} <= {?ParamDateTo}
Use a ParameterRangeValue instead of a ParameterDiscreteValue, and set the StartValue and EndValue properties to your start and end dates.
Update:
Here's some sample code that worked on a test report:
ParameterFieldDefinitions paramDefinitions = report.DataDefinition.ParameterFields;
ParameterFieldDefinition paramDefinition = paramDefinitions["DateRange"];
ParameterValues paramValues = paramDefinition.CurrentValues;
ParameterRangeValue rangeValue = new ParameterRangeValue();
rangeValue.StartValue = new DateTime(2010, 10, 31);
rangeValue.EndValue = new DateTime(2010, 12, 15);
paramValues.Add(rangeValue); ;
paramDefinition.ApplyCurrentValues(paramValues);
Make sure that your MyParameter is a range value, and that the select statement in Crystal is dateField = {?MyParameter}