本文介绍了无法从Window窗体中的Acess数据库中执行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个表jobmaster表,其中包含一个字段发货日期(日期/时间类型为短时格式),在Windows窗体中,我想调用表格中的所有数据 shipping date = value 。 我尝试了很多。 (在访问数据库中) I had a table jobmaster table with a field shipment date(date/time type in shorttime format) and in a windows form I want to call all data from the table where shipment date = value from a data picker.I tried a lot with it. (in access database )shipmentdate =Date/Time; format=Short Date///////////////////////in c# coding<pre>class jobcodedatabean{dateTime shipmentdate;//also have property} /////////////////////////// 日期时间选择器 dtpshipmentdate; format = short; 分配 ///////////////////////////datetime picker dtpshipmentdate;format=short;assigningjobcodedatabean.shipmentdate=dtpshipmentdate.value;insert into jobmastertable (shipment date)values('"jobcodedatabean.shipmentdate"') 现在在我的函数中我想从表中选择所有数据 i used Now in my function i want to select all data from tablei usedDateTime time = dtpfromDate.Value; String query = "Select jobcode,companyName,vehicleno,shipmentdate,totalamount,advance,drivername,fromPlace,destination from jobmastertable where (shipmentdate=" + @shipmentdate + ")"; OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);dAdapter.SelectCommand.Parameters.AddWithValue("@shipmentdate", time);DataSet ds = new DataSet(); dAdapter.Fill(ds, "tbljobmastertable");tblpaymentview.DataSource = ds.Tables["tblpaymentview"].DefaultView; 帮助我。什么都不返回。Help me. This returns nothing .推荐答案 DateTime包括小时,分钟,秒甚至毫秒,因此您要查找的记录不太可能与毫秒匹配。因此,您需要查找在所选日期内随时匹配的记录。假设datepicker返回一个代表某一天午夜的值。您需要查找大于日期但小于日期加一天的所有记录。 字符串查询=选择...其中(shipmentdate => @startdate AND shipmentdate =< @endDate); dAdapter.SelectCommand.Parameters.AddWithValue(@ startdate,time); dAdapter.SelectCommand.Parameters。 AddWithValue(@ endDate,time.AddDays(1)); DateTime includes hours, minutes, seconds and even milliseconds so it is unlikely that the records you are looking for will match to the millisecond. So you need to find records that match anytime during the selected day. Assuming the datepicker is returning a value which represents midnight on a given day. You will want to find all records greater than the date but less than the date plus one day.String query = "Select... where (shipmentdate => @startdate AND shipmentdate =< @endDate)";dAdapter.SelectCommand.Parameters.AddWithValue("@startdate", time);dAdapter.SelectCommand.Parameters.AddWithValue("@endDate", time.AddDays(1)); 改变参数值时间 CHANGED THE PARAMETER VALUE TIME FROM DateTime time = dtpfromDate.Value; TO TO DateTime time = dtpfromDate.Value.DATE; 这篇关于无法从Window窗体中的Acess数据库中执行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 09:34