question

nigelsvisionnigelsvision-3514 avatar image
0 Votes"
nigelsvisionnigelsvision-3514 asked XingyuZhao-MSFT commented

VB.NET extracting data from MySql in to a graph

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

dotnet-visual-basicwindows-forms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @nigelsvisionnigelsvision-3514 ,
May I know if you have got any chance to check my reply? Please let me know if you need further help.

0 Votes 0 ·

1 Answer

XingyuZhao-MSFT avatar image
0 Votes"
XingyuZhao-MSFT answered

Hi @nigelsvisionnigelsvision-3514 ,
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.



3.png (8.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.