VB.NET extracting data from MySql in to a graph

nigelsvision nigelsvision 96 Reputation points
2021-09-25T19:59:39.013+00:00

Hi, I have been experimenting with graphs in a windows form using VB.NET

I have had some success as I can now extract data in to my graph.

I created a windows form and dragged a chart on to it using Visual studio 2019. I then placed a button on the form. Inside the button click I have this code.

In my database table I have a column called company and a column called id, the code below successfully extracts the data. But I have now placed a label on my form that labels text shows a specific company name i.e. 'roman.plc'

How can I get my chart to only show data that matches the company name in the label. Because at the moment it shows all company names in the table.

 Try
            Using con As New MySqlConnection("server=Server ip; userid=User; password=MyPassword; database=DatabaseName")
                cmd.Connection = con
                cmd.CommandText = ("select * FROM Registrations ")
                con.Open()
                Dim reader = cmd.ExecuteReader()
                While reader.Read()
                    Chart1.Series("COMPANY_V_ID").Points.AddXY(reader.GetString("Company"), reader.GetInt32("id"))

                End While
                con.Close()
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Thanks

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,838 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,580 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xingyu Zhao-MSFT 5,356 Reputation points
    2021-09-27T06:08:50.6+00:00

    Hi @nigelsvision nigelsvision ,
    I make a test on my side, and you can refer to the following code:

            Using con As New SqlConnection(connString)  
                cmd.Connection = con  
                cmd.CommandText = ("select * FROM Registrations")  
                con.Open()  
                Dim reader = cmd.ExecuteReader()  
                While reader.Read()  
                    If reader.GetString("Company").Trim().Equals(Label1.Text) Then  
                        Chart1.Series("COMPANY_V_ID").Points.AddXY(reader.GetString("Company"), reader("id"))  
                    End If  
                End While  
            End Using  
    

    Result of my test:
    135472-3.png
    Hope it could be helpful.

    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments