アクセスデータベースのレコードを検索してアーカイブを選択できるフォームを作成しましたが、更新スクリプトを取得できないようです上記のクエリで返されたレコードを実際に更新します。検索したレコードを更新できるフォームを作成しようとしています
誰かが助けることができますか?
おかげ
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 * FROM Contacts WHERE Archived = 0 AND (Surname = '" + textBox3.Text + "' OR Initial = '" + textBox3.Text + "' OR [Post Town] = '" + textBox3.Text + "' OR [Post Code] = '" + textBox3 + "')", conn);
command.Parameters.Add(new OleDbParameter("@Name", textBox3));
OleDbDataReader reader = command.ExecuteReader();
LoopThroughRecs(reader);
// Insert code to process data.
}
finally
{
conn.Close();
}
}
private void LoopThroughRecs(OleDbDataReader Data)
{
if (Data.Read())
{
customid.Text = Data["CustID"].ToString();
FirstName.Text = Data["Initial"].ToString();
LastName.Text = Data["Surname"].ToString();
Address1.Text = Data["Address 1"].ToString();
Address2.Text = Data["Address 2"].ToString();
Address3.Text = Data["Address 3"].ToString();
TownCity.Text = Data["Post Town"].ToString();
PostCode.Text = Data["Post Code"].ToString();
Telephone.Text = Data["Telephone"].ToString();
}
}
private void button3_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("UPDATE tblContacts SET Archived = 1 WHERE CustID = "CustID");
command.Parameters.Add(new OleDbParameter("@ID", customid));
}
finally
{
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;
conn.Close();
MessageBox.Show("Customer Archived");
}
}
}
}
ありがとうございました!残念ながらそれはまだ機能していません - 検索ボックスに値を返さない – Lives