Click here to Skip to main content
15,920,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This i coded
C#
dataGridView1.Rows.Clear();
            connect.ConnectionString = Tool.getStringDB(set.dbname, set.versionaccess);
            connect.Open();


            cmd.Connection = connect;
            cmd.CommandText = "SELECT * From InvoiceInformation WHERE Order_date between '" + startdate + "' and '"+enddate+"'";

            OleDbDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                dataGridView1.Rows.Add();

                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Invoice_no"].Value = reader[0].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Purchase_ProductID"].Value = reader[1].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Purchase_ProductName"].Value = reader[2].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Purchase_Amout"].Value = reader[3].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Purchase_TotalPay"].Value = reader[4].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Order_date"].Value = reader[5].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Customer_name"].Value = reader[6].ToString();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Address"].Value = reader[7].ToString();
            }
            connect.Close();

startdate and enddate = datetimepicker

i got this error
Data type mismatch in criteria expression.
in
OleDbDataReader reader = cmd.ExecuteReader();
Posted

1 solution

I think you face issue in bellow statement (If Cell [Order_Date] is datetime type)

dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Order_date"].Value = reader[5].ToString();

You are trying to put string value in DateTime datatype object.
try to convert reader[5] value into date time like

C#
DateTime myDate = DateTime.ParseExact(reader[5].ToString(), "yyyy-MM-dd HH:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture)

 dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Order_date"].Value=myDate;
 
Share this answer
 
Comments
KururuLABO 4-Sep-13 2:10am    
But i executereader normal(I mean exereader can use not between cmd) can working -0-

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