0

I have problem to fill grid in c#

OleDbCommand cmd = new OleDbCommand("SELECT data.acno, data.BillNo AS, data.Name,
Sum([Price]*[qty]) AS ટોટલ FROM data INNER JOIN agro ON data.BillNo = agro.BillNo 
GROUP BY data.acno, data.BillNo, data.Name, data.db, data.Date HAVING 
(((data.db)='true') AND ((data.Date) = '" + coGuj(drpDate.Text) + "'))", con);

DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
viewgrid_credit.DataSource = ds.Tables[0];

This code write to fill grid but no arise any error not fill grid only display heading of grid but not return require output.

Query is 100% correct this query run in access successfully and also return result.

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
Hiren Raiyani
  • 754
  • 2
  • 12
  • 28

2 Answers2

0

1) Try debugging it and set a break-point at :

da.fill(ds) 

to see if any data is returned.

2) If that does not work, I will suggest breaking the query down and using a few simple queries first.

    var cmd = new OleDbCommand("SELECT data.acno, data.BillNo, data.Name,
                                Sum([Price]*[qty]) AS ટોટલ 
                                FROM data", con);

    var ds = new DataSet();
    var da = new OleDbDataAdapter(cmd);
    da.Fill(ds);
    viewgrid_credit.DataSource = ds.Tables[0];

See if this works and then append your extra query.

Alok
  • 1,290
  • 1
  • 11
  • 21
0

There is only single mistake (but that not mistake becasue in access that is return result properly). When we fire query directly in access then '*' is allowed to pattern matching but in C# that compulsory to use '%' require.

Hiren Raiyani
  • 754
  • 2
  • 12
  • 28