如何解决输入数组的长度比列数多? [英] How to solve Input array is longer than the number of columns ?

查看:148
本文介绍了如何解决输入数组的长度比列数多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 protected void Add_Click(object sender, EventArgs e)
        {
            GridView1.Visible = true;
            //createnewrow();
            ds.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text);/*here Input is no longer than the number of columns*/

            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";

            GridView1.DataSource = ds;
            GridView1.DataBind();
            GridView1.DataSource = null;

        }




推荐答案

你在问什么当输入数组太长时,你会给我们一个例子,说明最坏的情况不会发生吗? 

You're asking what to do when the input array is too long, but you gave us an example where this worst case does not happen? 

要避免ArgumentException,其中数组大于在表中的列之前,您可以在将DataRowCollection.Add()方法应用于它之前检查数组的长度。

To avoid an ArgumentException, where the array is larger than the number of columns in your table, you could check for the length of your array before applying the DataRowCollection.Add() method to it.

object[] objects = ...;
if(objects.Length > 3)
{
    //Do sth., e.g. issue a warning and return.
}


wizend

wizend


这篇关于如何解决输入数组的长度比列数多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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