Click here to Skip to main content
15,913,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

my gridview is not showing data,
i checked with breakpoints, datatable is showing data but gridview is not showing,.query is correct, runed on Mysql workbench.


C#
<pre lang="c#">  using (MySqlConnection con = new MySqlConnection(ConnectionString))
            {
                String query = "select * from transaction where DATE(paid_date)BETWEEN '" + fromdate + "'AND'" + todate + "' AND(customer_id='" + customer + "' OR card_id='" + card + "')";
                con.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(query, con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
                //dataGridView1.DataBind();

                           
                           
            }
Posted

C#
{
    String query = "select * from transaction where DATE(paid_date)BETWEEN '" + fromdate + "'AND'" + todate + "' AND(customer_id='" + customer + "' OR card_id='" + card + "')";
    con.Open();
    MySqlDataAdapter da = new MySqlDataAdapter(query, con);
    DataTable dt = new DataTable();
    da.Fill(dt);
    dataGridView1.DataSource = dt;
    dataGridView1.DataBind();
}

Uncomment the DataBind(). Because after assigning the source to the GridView, you must bind the data to it, so that GridView can hold the data within it.

-KR
 
Share this answer
 
Comments
Member 10263519 18-Feb-14 23:43pm    
if i uncomment it, it's giving error as

Error 1 'System.Windows.Forms.DataGridView' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?)
Member 10263519 18-Feb-14 23:44pm    
it's windows application
Krunal Rohit 19-Feb-14 0:11am    
You should have mentioned that first. Okay let me see what I can do.
-KR
Uncomment the DataBind line and read up on it:
[^]
 
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