我想設置一個方法,允許我存檔已經通過搜索框返回的記錄。在Access數據庫存檔客戶C#
我已經使搜索查詢正常工作,但是當我運行更新查詢時,記錄在搜索時仍然出現。
有人可以幫忙嗎?
namespace Test_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
MainMenu MMform = new MainMenu();
MMform.Show();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BoilerSvc_be.mdb";
try
{
conn.Open();
OleDbCommand command = new OleDbCommand("SELECT Equipment.CustID AS CustID,Equipment.Manufacturer AS Manufacturer,Equipment.Model AS Model, Equipment.LastService AS LastService,Initial,Surname,[Address 1],[Address 2],[Address 3],[Post Town],[Post Code],Telephone FROM Contacts INNER JOIN Equipment ON Equipment.CustID = Contacts.CustID WHERE Contacts.Archived = 0 AND Surname = '" + textBox3.Text + "' OR Initial = '" + textBox3.Text + "' OR[Post Town] = '" + textBox3.Text + "' OR[Post Code] = '" + textBox3 + "'", conn);
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int result;
customid.Text = reader["CustID"].ToString();
FirstName.Text = reader["Initial"].ToString();
LastName.Text = reader["Surname"].ToString();
Address1.Text = reader["Address 1"].ToString();
Address2.Text = reader["Address 2"].ToString();
Address3.Text = reader["Address 3"].ToString();
TownCity.Text = reader["Post Town"].ToString();
PostCode.Text = reader["Post Code"].ToString();
Telephone.Text = reader["Telephone"].ToString();
LstSvcDat.Text = reader["LastService"].ToString();
BoilMan.Text = reader["Manufacturer"].ToString();
BoilMod.Text = reader["Model"].ToString();
result = Convert.ToInt32(customid.Text);
}
}
finally
{
conn.Close();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(LastName.Text))
{
MessageBox.Show("Please Search for a Customer First");
}
else
{
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BoilerSvc_be.mdb";
try
{
conn.Open();
OleDbCommand command = new OleDbCommand("UPDATE Contacts SET Archived = 1 WHERE CustID = @CustID", conn);
command.Parameters.Add(new OleDbParameter("@PCustID", customid.Text));
OleDbDataReader reader = command.ExecuteReader();
}
finally
{
conn.Close();
customid.Text = null;
FirstName.Text = null;
LastName.Text = null;
Address1.Text = null;
Address2.Text = null;
Address3.Text = null;
TownCity.Text = null;
PostCode.Text = null;
Telephone.Text = null;
LstSvcDat.Text = null;
BoilMan.Text = null;
BoilMod.Text = null;
MessageBox.Show("Customer Archived");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
您是否檢查過表以確認存檔字段已更改?另外,確保存檔字段具有正確的數據類型。 –