简体   繁体   中英

adding data from textbox to datatable in vb.net

I am trying to input data from a textbox to a datatable, but I cant seem to get it working properly. I have tried variables, objects, array and subroutines. none of the mentioned has worked out.

The program is simply a chart generator, it takes 5 variables from 5 textboxes and input them into a datatable in order to populate a line chart.

Dim dtTest As New DataTable
Dim a As Integer

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    dtTest.Columns.Add("Grades", GetType(Integer))
    dtTest.Columns.Add("Exams", GetType(Integer))

    dtTest.Rows.Add(1, a) // **it wont work with variables**
    dtTest.Rows.Add(2, 80) // 
    dtTest.Rows.Add(3, 60)
    dtTest.Rows.Add(4, 90)
    dtTest.Rows.Add(5, 70)

    With Chart1.ChartAreas(0)
        .AxisX.Minimum = 0
        .AxisX.Maximum = 6
        .AxisY.Minimum = 50
        .AxisY.Maximum = 100
        .AxisY.Interval = 10
        .AxisX.Title = "Grades"
        .AxisY.Title = "Exams"
    End With

End Sub

any help would highly be appreciated

After some testing my guess is that your problem is the lack of displayed data in the Chart. Add this (If you dont do the first line then "Derp" needs to be changed to "Series1" in the bottom two lines.):

    Chart1.Series("Series1").Name = "Derp"
    Chart1.Series("Derp").XValueMember = "Grades"
    Chart1.Series("Derp").YValueMembers = "Exams"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM