简体   繁体   English

在vb.net中将数据从文本框添加到datatable

[英]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. 该程序只是一个图表生成器,它从5个文本框中获取5个变量,并将它们输入到数据表中以填充折线图。

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.): 添加此内容(如果您不执行第一行,则需要在最后两行中将“ Derp”更改为“ Series1”。):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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