private void button2_Click(object sender, EventArgs e) { //MessageBox.Show("1'" + Lname + "'", textBox2.Text.ToString()); //MessageBox.Show("2'" + Fname + "'", textBox3.Text.ToString()); //MessageBox.Show("3'" + Age + "'", textBox4.Text.ToString()); //MessageBox.Show("4'" + Gender + "'", comboBox1.Text.ToString()); if (Lname.Equals(textBox2.Text) && Fname.Equals(textBox3.Text) && Age.Equals(textBox4.Text) && Gender.Equals(comboBox1.Text)) { MessageBox.Show("Өөрчлөлт хийгдээгүй байна"); } else { int affectedRows = 0; string connetionString = null; connetionString = "Data Source=MD\\SQLEXPRESS;Initial Catalog=lab;Integrated Security=True"; // connetionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SqlConnection con = new SqlConnection(connetionString); SqlCommand cmd = new SqlCommand(); //string myQuery = "INSERT INTO dbo.Employees (Name, DoB, Gender, Address, AddedBy, AddedDate) VALUES(@Name, @DoB, @Gender, @Address, @AddedBy, @AddedDate)"; string myQuery = "dbo.UpdateEmployee"; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = myQuery; cmd.Parameters.Add("@id", SqlDbType.NChar); cmd.Parameters.Add("@dob", SqlDbType.Date); cmd.Parameters.Add("@lname", SqlDbType.NChar); cmd.Parameters.Add("@fname", SqlDbType.NChar); cmd.Parameters.Add("@gender", SqlDbType.NChar); cmd.Parameters.Add("@age", SqlDbType.Int); cmd.Parameters["@id"].Value = textBox1.Text; cmd.Parameters["@dob"].Value = DB.Value; cmd.Parameters["@lname"].Value = textBox2.Text; cmd.Parameters["@fname"].Value = textBox3.Text; cmd.Parameters["@gender"].Value = comboBox1.Text; cmd.Parameters["@age"].Value = Int32.Parse(textBox4.Text); SqlParameter sqlP = cmd.Parameters.Add("@ReturnValue", SqlDbType.Int); sqlP.Direction = ParameterDirection.ReturnValue; try { cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); affectedRows = (int)cmd.Parameters["@ReturnValue"].Value; if (affectedRows == 0) { MessageBox.Show("Амжилттай хадгалагдлаа"); cmd.Dispose(); con.Close(); data(); } else if (affectedRows == 1) { MessageBox.Show("Хадгалагдсангүй", "Алдаа"); } else { cmd.Dispose(); con.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); cmd.Dispose(); con.Close(); } } }