Answers for "input array is longer than the number of columns in this table. c#"

C#
1

input array is longer than the number of columns in this table. c#

//solution 1
//You are trying to add more number of column values to the dataRow,
ds.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text);
//heck the columns count and add correct number of column values
int colsCount =  dt.Columns.Count;
//refer this example:
DataTable dt = new DataTable();
       dt.Columns.Add("Col1");
       dt.Rows.Add("Col1 Data"); // Valid
       dt.Rows.Add("Col1 Data", "Col2 Data"); // invalid ,  Input array is longer than the number of columns

//solution 2
protected void Add_Click(object sender, EventArgs e)
{
    GridView1.Visible = true;
    //createnewrow();
    ds.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text);

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

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

}
Posted by: Guest on August-28-2021

Code answers related to "input array is longer than the number of columns in this table. c#"

C# Answers by Framework

Browse Popular Code Answers by Language