PDA

View Full Version : مشکل درج سطرهای تکراری



programerinfonet
پنج شنبه 02 خرداد 1392, 11:06 صبح
سلام دوستان
من تو برنامم وقتی یک سطر از دیتاگرید رو انتخاب می کنم و ویرایشش می کنم بجای اینکه همون ویرایش بشه یه سطر دیگه به دیتاگرید اضافه میشه و باید فرم رو ببندم و دوباره باز کنم تا درست بشه
مشکل کارم کجاست
لطفأ کمک کنید
بانکم هم اکسسه

khokhan
پنج شنبه 02 خرداد 1392, 11:12 صبح
سلام دوستان
من تو برنامم وقتی یک سطر از دیتاگرید رو انتخاب می کنم و ویرایشش می کنم بجای اینکه همون ویرایش بشه یه سطر دیگه به دیتاگرید اضافه میشه و باید فرم رو ببندم و دوباره باز کنم تا درست بشه
مشکل کارم کجاست
لطفأ کمک کنید
بانکم هم اکسسه

سلام

می شه کد مربوط به آپدیت جدول رو بگزاری ببینیم

programerinfonet
پنج شنبه 02 خرداد 1392, 11:30 صبح
این کد مقادیر دیتاگرید رو میفرسته تو فرم بعدی واسه آپدیت
try
{
Form4 varzeshkaran = new Form4();
varzeshkaran.state = "edit";
varzeshkaran.shenase = dataGridView1.CurrentRow.Cells[0].Value.ToString();
varzeshkaran.textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
varzeshkaran.textBox2.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
varzeshkaran.textBox3.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
varzeshkaran.textBox4.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
varzeshkaran.textBox5.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
varzeshkaran.textBox6.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
varzeshkaran.textBox7.Text = dataGridView1.CurrentRow.Cells[7].Value.ToString();
varzeshkaran.ShowDialog();
show();


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

این کد نمایش تو دیتاگرید

DataSet ds = new DataSet();
public void show()
{
try
{
OleDbDataAdapter adap = new OleDbDataAdapter("select * from varzeshkaran", con);
adap.Fill(ds, "varzeshkaran");
dataGridView1.DataSource = ds.Tables["varzeshkaran"];
dataGridView1.Columns["id"].HeaderText = "کد";
dataGridView1.Columns["vname"].HeaderText = "نام ورزشکار";
dataGridView1.Columns["mcod"].HeaderText = "کد ملی";
dataGridView1.Columns["bdate"].HeaderText = "تاریخ تولد ";
dataGridView1.Columns["tell"].HeaderText = "تلفن تماس";
dataGridView1.Columns["address"].Visible = false;
dataGridView1.Columns["disc"].Visible = false;
dataGridView1.Columns["rdate"].HeaderText = "زمان ثبت نام";
dataGridView1.Columns["id"].Width = 50;
dataGridView1.Columns["vname"].Width = 150;

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


و اینم کد آپدیت

try
{
if (state == "new")
{
OleDbCommand cmdoledb = new OleDbCommand("INSERT into varzeshkaran(vname,mcod,bdate,tell,address,disc,rd ate) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')", con);
cmdoledb.ExecuteReader();
MessageBox.Show("مشخصات جدید به ثبت رسید", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
if (state == "edit")
{

OleDbCommand uq = new OleDbCommand("update varzeshkaran set vname='" + textBox1.Text + "',mcod='" + textBox2.Text + "',bdate='" + textBox3.Text + "',tell='" + textBox4.Text + "',address='" + textBox5.Text + "',disc='" + textBox6.Text + "',rdate='" + textBox7.Text + "' where id=" + shenase + "", con);
uq.ExecuteNonQuery();
MessageBox.Show("عملیات ویرایش انجام شد", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

OleDbCommand dbc = new OleDbCommand("Select id from varzeshkaran where mcod='" + textBox2.Text + "'", con);
ids = dbc.ExecuteScalar().ToString();
stiReport1.Dictionary.Variables["Variable1"].Value = textBox1.Text;
stiReport1.Dictionary.Variables["Variable2"].Value = textBox2.Text;
stiReport1.Dictionary.Variables["Variable3"].Value = textBox3.Text;
stiReport1.Dictionary.Variables["Variable4"].Value = textBox5.Text;
stiReport1.Dictionary.Variables["Variable5"].Value = textBox4.Text;
stiReport1.Dictionary.Variables["Variable6"].Value = textBox7.Text;
stiReport1.Dictionary.Variables["Variable7"].Value = textBox6.Text;
stiReport1.Dictionary.Variables["Variable8"].Value = ids;
stiReport1.Show();

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

programerinfonet
پنج شنبه 02 خرداد 1392, 13:59 عصر
نبود کسی ؟
کمک کنید

programerinfonet
پنج شنبه 02 خرداد 1392, 14:08 عصر
خودم مشکلو فهمیدم
تو قسمت show نباید متد dataset رو خارج از بدنه ی سیکنتکس معرفی می کردم