PDA

View Full Version : مبتدی: مشکل در حذف اطلاعات از اکسس



shytonak
دوشنبه 07 آذر 1390, 21:54 عصر
دوستان من از کد زیر برای پاک کردن یک سطر خاص در اکسس استفاده کردم اما متاسفانه جواب نمی ده.
string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Environment.CurrentDirectory + "\\DataBase.accdb";

if (MessageBox.Show("آیا مایلید مورد انتخاب شده حذف شود؟", "سوال(حذف)؟", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
string a = dataGridView1.CurrentRow.Cells[0].Value.ToString();
string b = dataGridView1.CurrentRow.Cells[1].Value.ToString();
string c = dataGridView1.CurrentRow.Cells[2].Value.ToString();
string d = dataGridView1.CurrentRow.Cells[3].Value.ToString();
string e1 = dataGridView1.CurrentRow.Cells[4].Value.ToString();
string f = dataGridView1.CurrentRow.Cells[5].Value.ToString();
string g = dataGridView1.CurrentRow.Cells[6].Value.ToString();
string h = dataGridView1.CurrentRow.Cells[7].Value.ToString();
string j = dataGridView1.CurrentRow.Cells[8].Value.ToString();

OleDbConnection ocn = new OleDbConnection(ConnectionString);
OleDbCommand ocm = new OleDbCommand();

ocm.CommandText = "DELETE FROM costomer WHERE name=@name and group=@group AND number=@number AND monyget=@monyget AND monypaid=@monypaid AND phone=@phone AND adress=@adress AND email=@email AND date=@date";
ocm.Parameters.Clear();
ocm.Parameters.AddWithValue("@name", a);
ocm.Parameters.AddWithValue("@group", b);
ocm.Parameters.AddWithValue("@number", c);
ocm.Parameters.AddWithValue("@monyget", e1);
ocm.Parameters.AddWithValue("@monypaid", f);
ocm.Parameters.AddWithValue("@adress", g);
ocm.Parameters.AddWithValue("@email", h);
ocm.Parameters.AddWithValue("@date", j);

ocm.Connection = null;
ocm.Connection = ocn;

ocn.Open();
ocm.ExecuteNonQuery();
ocn.Close();

ocm.Dispose();
ocn.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}