PDA

View Full Version : سوال: حذف کردن داده



yasin5
یک شنبه 10 دی 1391, 18:00 عصر
با سلام در کد زیر با اینکه در اجرا بر روی No کلیک می کنم ولی باز هم داده ها حذف می شوندمشکل کجاست

SqlConnection scn = new SqlConnection();
scn.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + @"\Hospital.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand scd = new SqlCommand();
scd.Connection = scn;
scd.CommandText = " delete from [Pezeshk]where code = " + System.Convert.ToInt32(maskedTextBox1.Text) + "";
dataGridView1.Rows.Remove(dataGridView1.CurrentRow );
scn.Open();
scd.ExecuteNonQuery();
if (MessageBox.Show("ایا اطمینان به حذف کردن دارید", "حذف", MessageBoxButtons.YesNo) ==DialogResult.Yes)


scn.Close();

سعید کشاورز
یک شنبه 10 دی 1391, 18:06 عصر
خوب به خاطر اینه که اول داده ها رو حذف میکنی بعدش از کاربر سوال میکنی میخای حذفش کنم :لبخند:

کد زیر رو نگاه کن

Book clsBook = new Book();
clsBook.Id = int.Parse(DgvBook["id", DgvBook.CurrentRow.Index].Value.ToString());
DialogResult DR = MessageBox.Show("برای حذف اطمینان دارید؟", "هشدار", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (DR == DialogResult.Yes)
{
clsBook.DeleteBook();
ShowDataBook();
}

yasin5
یک شنبه 10 دی 1391, 18:19 عصر
لطف می کنید در کدی که خودم نوشتم بنویسید

khokhan
یک شنبه 10 دی 1391, 19:48 عصر
لطف می کنید در کدی که خودم نوشتم بنویسید


بفرما اينم كد شما :متعجب:


private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("ایا اطمینان به حذف کردن دارید؟", "حذف", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{


SqlConnection scn = new SqlConnection();
scn.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + @"\Hospital.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand scd = new SqlCommand();
scd.Connection = scn;
scd.CommandText = " delete from [Pezeshk]where code = " + System.Convert.ToInt32(maskedTextBox1.Text) + "";
dataGridView1.Rows.Remove(dataGridView1.CurrentRow );
scn.Open();
scd.ExecuteNonQuery();

scn.Close();
MessageBox.Show("Deleted");
}
else { }
}