PDA

View Full Version : پیغام برای تکراری بودن اطلاعات



xxxsenatorxxx
یک شنبه 13 فروردین 1391, 23:40 عصر
ا سلام و خسته نباشید
در فرم add با چند تکست باکس و دیتا بیس اکسس میخواهیم پیغام بده اطلاعات وارد شده قبلا ثبت شده یعنی پیغام تکراری بودن اطلاعات رو بده
چندتا روش گشتم پیدا کردم ولی یا کار نمیکنه یا خطا میده
یه کمکی بکنید. یه راه خوب که کار کنه بگید.ممنون


try
{

OleDbException ex;
if (ex.ErrorCode == -2147467259)
{
Program.HandleException(ex, false, null);
MessageBox.Show("اطلاعات این فرد قبلا ثبت شده است");
}
else
{
Program.HandleException(ex, true, null);
}
}
catch
{






OleDbCommand dps = new OleDbCommand();
dps.CommandText = "select post,name,family,number,comment from DBA where code= " + comboBox1.Text + " and name = " + textBox2.Text + " and family = " + textBox3.Text + " and number = " + textBox4.Text + " and comment = " + textBox5.Text + " ";
dps.Parameters.Add(new OleDbParameter("number", textBox4.Text));
dps.Connection = oleDbConnection1;
d = dps.ExecuteNonQuery();
if (d > 0)
MessageBox.Show(" تکراری");



int tekrari = 0; oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "select code,name,family,number,comment from DBA where code = " + comboBox1.Text + " and name = " + textBox2.Text + " and family = " + textBox3.Text + " and number = " + textBox4.Text + " and comment = " + textBox5.Text + " ";
oleDbDataAdapter1.SelectCommand.ExecuteNonQuery();
tekrari = oleDbDataAdapter1.
if(tekrari != 0)
{
}

Death_2008
دوشنبه 14 فروردین 1391, 10:25 صبح
سلام
از جدولت یک Select با شرط یک از فیلدهات بگیر و اگر مقداری وجود داشت که اطلاعات تکراری است.(فیلد شرط باید کلید اصلی باشد)
موفق باشید

merlin_vista
دوشنبه 14 فروردین 1391, 12:43 عصر
cmd.CommandText = "if exists(select fCode from tbFingers where fCode=@fCode ) begin raiserror('کد اثر انگشت تکراری میباشد', 16, 1) end else begin insert into tbFingers (fCode,fType,tId) VALUES (@fCode,'T',@tId) end";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@fCode", txtFingerCode.Text);
cmd.Parameters.AddWithValue("@tId", tid);
cmd.ExecuteNonQuery();


سپس در قسمت Catch
catch (SqlException ex)
{
mytran.Rollback();
lib.WarningMessage(ex.Message);
}