创建多个数据表会导致失败 [英] Creating multiple datatables causes failures

查看:85
本文介绍了创建多个数据表会导致失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初编写代码来创建和填充一个包含233列的DataTable。

虽然代码成功运行,但我认为最好有三列38列,19列DataTables分别为10列。

但是,当我运行代码时,其中两个DataTable会引发错误,而第三个工作正常。 (我通过更改表格的创建顺序并在代码中填充来测试表格。

失败声明如下;



I originally wrote my code to create and populate a DataTable with some 233 columns.
Although the code worked successfully, I decided that it would be better to have three DataTables of 38 columns, 19 columns and 10 columns respectively.
However, when I run the code, two of the DataTables throws up an error whilst the third works correctly. ( I tested the tables by changing the order the tables were created and populated in the code)
The failure statement is as follows;

An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll

Additional information: Input array is longer than the number of columns in this table.







我的第二个表(YBTeamTable)的代码如下;






My code for the second table (YBTeamTable) is as follows;

Public YBResultsTable As DataTable = New DataTable()
Public YBTeamTable As DataTable = New DataTable()
Public YBRTable As DataTable = New DataTable()

Private Sub Team_Table()
    'Create a DataTable called YBTeamTable with ten columns
    YBTeamTable.Columns.AddRange(New DataColumn() {
        New DataColumn("TeamNumber", GetType(Integer)),
        New DataColumn("Player1", GetType(String)),
        New DataColumn("Player2", GetType(String)),
        New DataColumn("Player3", GetType(String)),
        New DataColumn("Player4", GetType(String)),
        New DataColumn("TeamTotal", GetType(Integer)),
        New DataColumn("Last9", GetType(Integer)),
        New DataColumn("Last6", GetType(Integer)),
        New DataColumn("Last3", GetType(Integer)),
        New DataColumn("LastHole", GetType(Integer))})

End Sub
Private Sub Add_Team_Totals()
    'Add the row to the data table of the team players and total scores plus count back
    'First copy 10 lots of data on form to associated variable.
    curTeamNumber = TeamNumberBox.Text
    Dim curPlayer1 As String = YBPlayer1.Text
    Dim curPlayer2 As String = YBPlayer2.Text
    Dim curPlayer3 As String = YBPlayer3.Text
    Dim curPlayer4 As String = YBPlayer4.Text
    Dim curTeamTotal As Integer = TeamTotal.Text
    Dim curLast9 As Integer = Last9Holes.Text
    Dim curLast6 As Integer = Last6Holes.Text
    Dim curLast3 As Integer = Last3Holes.Text
    Dim curLastHole As Integer = LastHole.Text

    'Add data to next row in table YBTeamTable
    YBTeamTable.Rows.Add(curTeamNumber, curPlayer1, curPlayer2, curPlayer3, curPlayer4, curTeamTotal, curLast9, curLast6, curLast3, curLastHole) 'Error states array too longer
End Sub





我创建了一个包含十列的表,并添加了一行包含十个数据。尽管播放器的名称确实包含空格,即John Smith,但没有数据包含逗号。但如果所有字符串都是空白且所有整数都为0,也会失败

有谁能告诉我哪里出错了?答案我愚蠢地忘了从加载文件中运行Sub例程。



I have created a table with ten columns and added a row with ten pieces of data. None of the data contains a comma although the Player's Name does contain a space i.e. "John Smith". But also fails if all strings are blank and all integers are 0
Can anyone tell me where I am going wrong? ANSWER I stupidly forgot to run the Sub routines from the load file.

推荐答案

确保你运行子例程


这篇关于创建多个数据表会导致失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆