Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
foreach (var item in resultSet)
                {
 
                    dataFeedTable.Rows.Add(item);
                }



Thanks in advance
Posted
Comments
Andy Lanng 24-Nov-15 7:29am    
what is "item"? What are it's contents
What columns are in dataFeedTable.Columns
Jawad Ahmed Tanoli 24-Nov-15 7:36am    
What is resultSet? how many columns in your datatable.
DataTable dt=new DataTable();
dt.Columns.Add("FName");
dt.Rows.Add(new object[] {"xyz" });
Booni Goal 11-May-21 5:54am    
populate();
populateproducts();
fillcategory();
DataTable table = new DataTable();
table.Columns.Add("Num", typeof(int));//datatype int
table.Columns.Add("Product", typeof(string));//datatype string
table.Columns.Add("Quantity", typeof(int));//datatype string
table.Columns.Add("UPrice", typeof(int));//datatype string
table.Columns.Add("Totprice", typeof(int));//datatype datetype int
OrderGv.DataSource = table;
}
int flag = 0;
private void ProductsGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
product = ProductsGV.SelectedRows[0].Cells[0].Value.ToString();
// qty = Convert.ToInt32(QtyTb.Text);
uprice = Convert.ToInt32(ProductsGV.SelectedRows[0].Cells[3].Value.ToString());
// totprice = qty * uprice;
flag = 1;
}

private void bunifuButton1_Click(object sender, EventArgs e)
{
if (QtyTb.Text == "")
MessageBox.Show("Enter The Quantity Of Product");
else if (flag == 0)
MessageBox.Show("Select The Product");
else
{
DataTable table = new DataTable();
num = num + 1;
qty = Convert.ToInt32(QtyTb.Text);
totprice = qty * uprice;
table.Rows.Add(num, product, qty, uprice, totprice);
OrderGv.DataSource = table;
flag = 0;


SIR THIS IS MY TABLE { TOTAL WANTS TO SEE IN THE TABLE BELOW}
THERE IS NO OPTION TO SENT YOU SCRRENSHORTS OF MY TABLE SIR MY PROJECT LONG TIME
HOLD THIS ERROR




1 solution

When you create a table, you declare a specific number of columns, with names, header text, datatype and so forth - and the number of columns must match the number of objects you are inserting as a row. If you have created 4 columns in your table, and try to add 5 items, the system doesn't know what to do with them all and you get an exception.

So use the debugger, and look at dataFeedTable and item and see how many columns you have to work with.

We can't do that for you - we can't run your code!
 
Share this answer
 
Comments
Booni Goal 11-May-21 5:49am    
DataTable table = new DataTable();
num = num + 1;
qty = Convert.ToInt32(QtyTb.Text);
totprice = qty * uprice;
table.Rows.Add(num, product, qty, uprice, totprice);
OrderGv.DataSource = table;
flag = 0;
how to fix Input array is longer than number of columns in this table.
this project on windows from
plase give me guide
OriginalGriff 11-May-21 6:47am    
You haven't added any columns to the table at all: so you can't add rows because it has no idea what type of column they should be!

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