【发布时间】:2013-10-19 19:07:02
【问题描述】:
我正在制作一个程序,让用户使用 dateTimePicker 选择两个日期,我想获取两个日期之间的日期。这是我目前的工作:希望你能理解我的问题..
我想用两个日期之间的日期填充列表框
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication7
{
public partial class PrintOptions : Form
{
public PrintOptions()
{
InitializeComponent();
}
OleDbCommand command = new OleDbCommand();
OleDbConnection connectionBilling = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Paul\Documents\Visual Studio 2010\Projects\WindowsFormsApplication7\WindowsFormsApplication7\bin\BillingComputation.accdb;Persist Security Info=False;");
OleDbConnection connectionOrder = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Paul\Documents\Visual Studio 2010\Projects\WindowsFormsApplication7\WindowsFormsApplication7\bin\OrderData.accdb;Persist Security Info=False;");
private void PrintOptions_Load(object sender, EventArgs e)
{
toolTip1.SetToolTip(dateTimePicker1, "Select the starting date of your desire data");
toolTip1.SetToolTip(label1, "Select the starting date of your desire data");
toolTip1.SetToolTip(dateTimePicker1, "Select the end date of your desire data");
toolTip1.SetToolTip(label1, "Select the end date of your desire data");
toolTip1.SetToolTip(groupBox1, "Select the database you want to print");
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
DateTime dt = this.dateTimePicker1.Value.Date;
DateTime dt2 = this.dateTimePicker2.Value.Date;
//Billing Data
if (radioButton1.Checked)
{
OleDbCommand commandqwe =new OleDbCommand ("SELECT DateOfTransaction "+String.Format("{0:dd/MM/yyyy}",dt)+" FROM BillingSystem WHERE((DateOfTransaction " + String.Format("{0:dd/MM/yyyy}", dt2) +"))",connectionBilling);
connectionBilling.Open();
OleDbDataReader reader = null;
reader = commandqwe.ExecuteReader();
while (reader.Read())
{
listBox1.Items.Add("DATE" + reader[4].ToString());
}
connectionBilling.Close();
}
}
}
}
【问题讨论】:
标签: c# select oledb ms-access-2010 datetimepicker