[英]Querying using data in table and local variables (C# and MS-Access, oledb)
I'm trying to Select data from a table using OLEDB
Libraries - Essentially I have a date range both dates in fields within a record (Access), I also have another field which is needed to select data. 我正在尝试使用
OLEDB
库从表中选择数据-本质上,我在记录(访问)中的字段中都有一个日期范围,两个日期也都存在,我还有一个字段需要选择数据。
I have a local variable holding date/time information, I need to output the data where that value held in the variable is in range with the two dates in a record, and the record holds another value which will be compared against a local variable. 我有一个保存日期/时间信息的本地变量,我需要输出数据,该变量中保存的值在记录中的两个日期的范围内,并且该记录保存另一个值,该值将与本地变量进行比较。 Any help, just showing basic syntax and querying would be appreciated.
任何帮助,只显示基本语法和查询将不胜感激。
I've looked for comparing and querying between date ranges and have had no luck. 我一直在寻找比较和查询日期范围之间的方法,但没有运气。
cmd.CommandText = "SELECT FirstName, LastName, Email, PhoneNumber,
NumberOfGuests, StartDate, NumberOfNights, Breakfast,
RoomType, EmployeeName, Comments FROM Booking WHERE
StartDate <= " + dtpRoomSearch.Value + "AND +
EndDate >= dtpRoomSearch.Value;
Need to output this information as a string (Excuse Bad Syntax, I don't know where I should be putting speech marks etc.) 需要将此信息输出为字符串(不好的语法,我不知道我应该在哪里放置语音标记等)
I need to Query using both Local Variables and Values held in the fields of a table ie StartDate ( addressing field in table ) and EndDate (Addressing Field in table compared with local values. Also, how would I go about structuring the syntax? 我需要使用表字段(即StartDate(表中的寻址字段)和EndDate(表中的寻址字段)与局部值比较)中保存的局部变量和值进行查询。此外,我将如何构造语法?
You need the correct syntax and format of the string expressions for the date values: 您需要日期值的字符串表达式的正确语法和格式:
cmd.CommandText = "SELECT FirstName, LastName, Email, PhoneNumber,
NumberOfGuests, StartDate, NumberOfNights, Breakfast,
RoomType, EmployeeName, Comments FROM Booking WHERE
StartDate <= #" + dtpRoomSearch.ToString("yyyy'/'MM'/'dd") + "# AND
EndDate >= #" + dtpRoomSearch.ToString("yyyy'/'MM'/'dd") + "#;"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.