简体   繁体   English

“row”参数不能为空。参数名称:row

[英]'row' argument cannot be null.Parameter name: row

I am trying to load back values from a CSV to my class .我正在尝试将值从CSV加载回我的class Then display the values to my datatable .然后显示的值,以我的datatable However, I get the error even after my values have been loaded into the class and placed inside the intended columns (See Figure 1 ).但是,即使我的值已加载到类中并放置在预期的列中,我也会收到错误消息(参见图1 )。 The error occurred at dt.Rows.Add(dr);错误发生在dt.Rows.Add(dr); . . Below is my code:下面是我的代码:

 public Newdatagrid()
    {
        InitializeComponent();

        //Do datatable
        ds = new DataSet();
        dt = new DataTable();
        dt.Columns.Add("Bus Model", typeof(string));//0
        dt.Columns.Add("Bus Type", typeof(string));//1
        dt.Columns.Add("Mileage", typeof(string));//2

        if (Savestate.vehnochange_list.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                dr["Bus Model"] = Savestate.busmodel_list[Savestate.busmodel_list.Count];//0
                dr["Bus Type"] = Savestate.bustype_list[Savestate.bustype_list.Count];//1
                dr["Mileage"] = Savestate.busmileage_list[Savestate.busmileage_list.Count];//2
            }

            dt.Rows.Add(dr);
            this.dataGridView2.DataSource = dt;

        }
   }

I think you want something like this:我想你想要这样的东西:

public Newdatagrid()
{
    InitializeComponent();

    //Do datatable
    ds = new DataSet();
    dt = new DataTable();
    dt.Columns.Add("Bus Model", typeof(string));//0
    dt.Columns.Add("Bus Type", typeof(string));//1
    dt.Columns.Add("Mileage", typeof(string));//2

    if (Savestate.vehnochange_list.Count > 0)
    {
        for (int i=0; i < Savestate.vehnochange_list.Count; ++i)
        {
            DataRow dr = dt.NewRow();
            dr["Bus Model"] = Savestate.busmodel_list[i];//0
            dr["Bus Type"] = Savestate.bustype_list[i];//1
            dr["Mileage"] = Savestate.busmileage_list[i];//2
            dt.Rows.Add(dr);
        }

        this.dataGridView2.DataSource = dt;

    }
}

暂无
暂无

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

相关问题 调整JPEG品质时出错:值不能为空参数名称:结构 - Error on adjusting jpeg quality: Value cannot be null.Parameter name: structure 无法使用 ASP.NET Identity 登录,值不能为空。参数名称:manager - Can not sign in using ASP.NET Identity, Value cannot be null.Parameter name: manager 值不能为null参数名称:在ASP.NET中进行数据绑定时的键 - Value cannot be null.Parameter name: key when databind in ASP.NET 值不能为null。参数名称:读取嵌入文件内容时出现流错误 - Value cannot be null.Parameter name: stream error while reading the contents of embeddded file &#39;table&#39;参数不能为null。 参数名称:表格 - 'table' argument cannot be null. Parameter name: table EPPlus - InsertRow: Row 不能小于 1. 参数名称: value - EPPlus - InsertRow: Row cannot be less than 1. Parameter name: value 错误指定的参数超出了有效值的范围。 参数名称:DataGridview Row Data Bound 中的索引 - Error Specified argument was out of the range of valid values. Parameter name: index in DataGridview Row Data Bound 从 C# 运行 PowerShell 脚本时出现错误“无法将参数绑定到参数‘Name’,因为它为空” - Error "Cannot bind argument to parameter 'Name' because it is null" when running PowerShell script from C# 值不能为空。 参数名称:extent - Value cannot be null. Parameter name: extent 值不能为空。 参数名称connectionString - Value cannot be null. Parameter name connectionString
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM