Click here to Skip to main content
15,888,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Im getting error here. anyone help where i had make mistake

What I have tried:

private DataTable Createds()
      {
          int i = 0;
          DataTable table = new DataTable("list");
          var _with1 = table.Columns;
          _with1.Add("FACESHEET_ID ", typeof(string));
          _with1.Add("ROW_NUMBER", typeof(string));
          _with1.Add("COLUMN_A", typeof(string));
          _with1.Add("COLUMN_B", typeof(string));
          _with1.Add("COLUMN_C", typeof(string));
          _with1.Add("COLUMNNAME_A", typeof(string));
          _with1.Add("COLUMNNAME_B", typeof(string));
          _with1.Add("COLUMNNAME_C", typeof(string));
          TextBox txt = default(TextBox);
          TextBox txtname = default(TextBox);
          var _with2 = table.Rows;
          for (i = 1; i <= DAL_Common.ADONullInt(ddlRow.SelectedValue); i++)
          {
              string[] vals = new string[9];
              txt = (TextBox)FindControl("txtdesc" + i + "" + 1 + "");
              vals[0] = hidID.Value;
              vals[1] = DAL_Common.ADONullString(i);
              vals[2] = txt.Text;
              if (DAL_Common.ADONullInt(ddlColumn.SelectedValue) > 1)
              {
                  txt = (TextBox)FindControl("txtdesc" + i + "" + 2 + "");
                  vals[3] = txt.Text;
              }
              else
              {
                  vals[3] = "";
              }

              if (DAL_Common.ADONullInt(ddlColumn.SelectedValue) > 2)
              {
                  txt = (TextBox)FindControl("txtdesc" + i + "" + 3 + "");
                  vals[4] = txt.Text;
              }
              else
              {
                  vals[4] = "";
              }
              txtname = (TextBox)FindControl("txtName" + i + "" + 1 + "");
              vals[5] = txtname.Text;
              if (DAL_Common.ADONullInt(ddlColumn.SelectedValue) > 1)
              {
                  txtname = (TextBox)FindControl("txtName" + i + "" + 2 + "");
                  vals[6] = txtname.Text;
              }
              else
              {
                  vals[6] = "";
              }

              if (DAL_Common.ADONullInt(ddlColumn.SelectedValue) > 2)
              {
                  txtname = (TextBox)FindControl("txtName" + i + "" + 3 + "");
                  vals[7] = txtname.Text;
              }
              else
              {
                  vals[7] = "";
              }
              _with2.Add(vals);
          }
          return table;
      }
Posted
Updated 4-May-17 1:35am

1 solution

You have 8 columns but an array of 9 strings:
C#
string[] vals = new string[9];
So change the array size to 8.
 
Share this answer
 
Comments
Member 13040174 4-May-17 8:15am    
thanks a lot!
Booni Goal 17-May-21 6:09am    
dear sir this code getting tabale but single rows
my code like this

please guide me how add rows

DataTable table1 = new DataTable("list");
var _with1 = table.Columns;
_with1.Add("Num ", typeof(int));
_with1.Add("product", typeof(string));
_with1.Add("qty", typeof(int));
_with1.Add("uprice", typeof(int));
_with1.Add("totprice", typeof(int));
table.Rows.Add(num, product, qty, uprice, totprice);
OrderGv.DataSource = table;
flag = 0;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900