Skip to content

Value doesnot show in datagridview

Atul Rokade

Asked Oct 10, 2016, 6:26 AM EDT1 answer
Share
LinkedInX
When i choose From Date and Todate from datetimepicker to show data in datagridview at that time datagridview show me empty data , code is written button click evet, here im using access database
 
 
Java
DateTime startT = new DateTime();
                DateTime endT = new DateTime();
                startT = dateTimePicker1.Value.Date;
                endT = dateTimePicker2.Value.Date;
                if (startT.Date > endT.Date)
                {
                    MessageBox.Show("To Date Cannot be greater than Start Date");
                }
                else
                {
                    string connetionString = null;
                    connetionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
                    con.ConnectionString = connetionString;

                    DataSet ds = new DataSet();
                    string sql = "SELECT Medicine_name,sum(Medicine_count) as Medicine_count,To_Date from Medicine_count_info where [To_Date] Between #" + startT.ToString("dd'/'MM'/'yyyy") + "#And #" + endT.ToString("dd'/'MM'/'yyyy") + "#group by Medicine_name,Medicine_count,To_Date order by Medicine_count desc ";
                    OleDbConnection connection = new OleDbConnection(connetionString);
                    OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
                    ds = new DataSet();
                    connection.Open();
                    dataadapter.Fill(ds);
                    connection.Close();
                    dataGridView1.DataSource = ds;
                    dataGridView1.DataMember = ds.Tables[0].TableName;
                    dataGridView1.Refresh();
}
 
 
 
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    hi i got a solution for this i used paramatarized query for this
    Java
     string sql = "SELECT Medicine_name,sum(Medicine_count) as Medicine_count,To_Date from Medicine_count_info where [To_Date] Between @startDate And @endDate group by Medicine_name,Medicine_count,To_Date order by Medicine_count desc";
                            OleDbConnection connection = new OleDbConnection(connetionString);
                            OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
                            dataadapter.SelectCommand.Parameters.AddWithValue("@startDate", startT);
                            dataadapter.SelectCommand.Parameters.AddWithValue("@endDate", endT);
                            ds = new DataSet();
                            connection.Open();
                            dataadapter.Fill(ds);
                            connection.Close();
                            dataGridView1.DataSource = ds;
                            dataGridView1.DataMember = ds.Tables[0].TableName;
    0