Click here to Skip to main content
15,888,337 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Guys, i am facing a issue and i dont know why i am getting this error and how to solve it please guide me how can i do this
i am getting error when i am get data in datagridview

What I have tried:

string query = "Select Product_Name As [ProductName],COUNT(ProductName) As [Qty],SUM(Price) As [Price] FROM [Sales Record] GROUP BY [Product Name]";
 using (OleDbConnection conn = new OleDbConnection(connStr))
 {
     using (OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn))
     {
         conn.Open();
         DataSet ds = new DataSet();
         if (ds != null)
         {

             adapter.Fill(ds);

             dataGridView1.DataSource = ds.Tables[0];
             conn.Close();
             dataGridView1.Rows[1].Visible = false;
             dataGridView1.Columns[0].Width = (150);
             dataGridView1.Columns[1].Width = (275);
             dataGridView1.Columns[2].Width = (250);
         }
     }
 }
Posted
Updated 2-Jan-17 19:13pm

1 solution

This error means: You are trying to fetch a field which doesn't exist in your database table.

please check your SQL.

string query = "Select Product_Name As [ProductName],COUNT(ProductName) As [Qty],SUM(Price) As [Price] FROM [Sales Record] GROUP BY [Product Name]";

you create alias of Product_Name as [ProductName] and after that you are trying to count that ProductName as quantity, I think this statement are suspicious to Me..:-)
Please check with your Table Fields name.
 
Share this answer
 

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