OlddbDataReader读取datetimepicker? [英] OlddbDataReader read datetimepicker ?

查看:74
本文介绍了OlddbDataReader读取datetimepicker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我编码的

This i coded

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和enddate = datetimepicker



i得到此错误

标准表达式中的数据类型不匹配。

in

OleDbDataReader reader = cmd.ExecuteReader();


startdate and enddate = datetimepicker

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

推荐答案

我认为你在下面的问题声明(如果Cell [Order_Date]是日期时间类型)



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



你试图将字符串值放在DateTime数据类型对象中。

尝试转换阅读器[5 ]值到日期时间如



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

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;


这篇关于OlddbDataReader读取datetimepicker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆