using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Globalization; namespace TelBook { public partial class fmnew : Form { public fmnew() { InitializeComponent(); } OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|DATA.ACCDB;JET OLEDB:DATABASE PASSWORD=●●●●●●●●●●●●;"); private void fmnew_Load(object sender, EventArgs e) { try { con.Open(); string d; OleDbDataAdapter adap; DataSet ds = new DataSet(); d = "select * from groups"; adap = new OleDbDataAdapter(d, con); adap.Fill(ds, "groups"); comboBox1.DataSource = ds.Tables["groups"]; comboBox1.DisplayMember = "groupname"; if (button1.Text == "ویرایش") { comboBox1.Text = label13.Text; } } catch (Exception ex) { MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void button1_Click(object sender, EventArgs e) { try { if (button1.Text == "ذخیره") { string cmdstr; oleDbCommand1.Parameters.Clear(); oleDbCommand1.CommandText = "Select fil2 from contact where code=@V"; oleDbCommand1.Parameters.AddWithValue("@V", Convert.ToInt32(fil2.Text)); oleDbConnection1.Open(); OleDbDataReader r = oleDbCommand1.ExecuteReader(); if (r.Read() == true) { fil7.Text = r["fil2"].ToString(); MessageBox.Show("کد تکراری است ", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } r.Close(); oleDbConnection1.Close(); OleDbCommand cmdoledb = new OleDbCommand(); cmdstr = "INSERT into contact(fil1,fil2,fil3,fil4,fil5,fil6,fil7,fil8,fil10,fil11,fil12,fil13) values('" + comboBox1.Text + "','" + fil2.Text + "','" + fil3.Text + "','" + fil4.Text + "','" + fil5.Text + "','" + fil6.Text + "','" + fil7.Text + "','" + fil8.Text + "','" + fil10.Text + "','" + fil11.Text + "','" + fil12.Text + "','" + fil13.Text + "')"; cmdoledb.Connection = con; cmdoledb.CommandText = cmdstr; cmdoledb.ExecuteReader(); MessageBox.Show("عملیات انجام شد", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (button1.Text == "ویرایش") { string updateq = "update contact set fil1='" + comboBox1.Text + "',fil2='" + fil2.Text + "',fil3='" + fil3.Text + "',fil4='" + fil4.Text + "',fil5='" + fil5.Text + "',fil6='" + fil6.Text + "',fil7='" + fil7.Text + "',fil8='" + fil8.Text + "',fil10='" + fil10.Text + "',fil11='" + fil11.Text + "',fil12='" + fil12.Text + "',fil13='" + fil13.Text + "'where id=" + textBox1.Text + ""; OleDbCommand uq = new OleDbCommand(updateq, con); uq.ExecuteNonQuery(); MessageBox.Show("عملیات ویرایش انجام شد", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void fil10_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("en")); } private void fil11_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil2_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil3_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil4_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil5_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil6_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil7_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil8_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil12_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void fil13_Enter(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("fa")); } private void label6_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void fil2_Leave(object sender, EventArgs e) { } } }
الآن مشکل دقیقاً کجاست ؟
چه اطلاعاتی باید تکراری نباشه؟ میتونی فیلدی که میخوای تکراری قبول نکنه رو از توی sql بصورت unique تعریف کنی. یا میتونی کلید تعریف کنی. یا میتونی قیبل از insert تو بانک وجود اون مقدار رو بررسی کنی و اگر قبلاً تو بانک بود پیغام بدی به کاربر. بیشتر توضیح بده که برنامت چیه .
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)