Access データベースとの間で情報を読み書きするプログラムを作成しました。
(以下のスクリーンショットとコードを参照)、それは問題なくうまく機能しますが、追加のボタンをクリックしてすべてのレコードを取得できるように拡張したいのですが、日付(または日付範囲)の入力を求めます最初。Access フォームまたは Access レポートでプロンプトを表示する方法は既に知っていますが、C# プログラムで日付の入力を求め、それをクエリに渡すようにしたいと考えています。写真のように、結果のウィンドウに表示します。これにより、レポートまたはフォームのフォームが開いているときに、ユーザーが Access を開く必要がなくなります。どんな助けでも大歓迎です、そしてどんな提案でも前もって感謝します!
namespace Health_Direct_Receiving
{
public partial class Form1 : Form
{
OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Receiving\Database.accdb");
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
{
vcon.Open();
}
}
private void button1_Click(object sender, EventArgs e)
{
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
{
MessageBox.Show("You must fill in all fields.");
return;
}
else
{
OleDbCommand dbCommand;
OleDbDataReader dbReader;
new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Receiving\Database.accdb");
dbCommand = new OleDbCommand("select count(*) as Record_Count from script_received", vcon);
dbReader = dbCommand.ExecuteReader();
if (dbReader.Read() == true)
rowCount = dbReader["Record_Count"].ToString();
else
return;
var date = DateTime.Now.ToString("MM/dd/yyyy");
{
using(OleDbCommand command = new OleDbCommand("INSERT INTO script_received (script, qty, emp_id, received_Date) VALUES (@script,@qty,@emp_Id,@rec_date)"))
{
command.CommandType = CommandType.Text;
command.Parameters.Add("@script", OleDbType.Integer).Value = textBox1.Text;
command.Parameters.Add("@qty", OleDbType.VarChar).Value = textBox2.Text;
command.Parameters.Add("@emp_id", OleDbType.VarChar).Value = textBox3.Text;
command.Parameters.Add("@rec_date", OleDbType.Date).Value = date;
command.Connection = vcon;
//vcon.Open();
command.ExecuteNonQuery();
}
this.textBox1.Clear();
this.textBox2.Clear();
this.textBox1.Focus();
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
new Form2().Show();
}
private void button3_Click(object sender, EventArgs e)
{
new Form3().Show();
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
public object rowCount { get; set; }
}
}
フォーム2
namespace Receiving
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.script_receivedTableAdapter.Fill(this.DatabaseDataSet.script_received);
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
フォーム3
namespace Receiving
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{ this.script_All_ReceivedTableAdapter.Fill(this.DatabaseDataSet.script_All_Received);
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}