示例#1
0
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(@"Server=.\SQLEXPRESS;Database=school;Integrated Security=true");

            conn.Open();
            string query = "";

            query = "INSERT INTO [employee] (name,designation,address,contact) VALUES('" + textName.Text + "','" + textDesig.Text + "','" + textAddress.Text + "'," + textContact.Text + ")";
            SqlCommand cmd = new SqlCommand(query, conn);

            try
            {
                int result = cmd.ExecuteNonQuery();
                if (result > 0)
                {
                    if (textName.Text != null && textDesig.Text != null && textAddress.Text != null && textDesig.Text != null)
                    {
                        MessageBox.Show("Successfully added!!!", "Succesfull");
                    }
                    else
                    {
                        MessageBox.Show("Please Fill All The Field!!!", "Incomplete");
                    }
                }
                else
                {
                    MessageBox.Show("error!!!", "Error");
                }
            }
            catch { MessageBox.Show("Please Fillup Correctly!!", "Error"); }
            conn.Close();
            h.RefreshEployeeTable();
        }
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("update [employee] set name = '" + textName.Text + "',designation = '" + textDesig.Text + "',address = '" + textAddress.Text + "',contact ='" + textContact.Text + "' where e_id = " + eid + "", conn);

            try
            {
                int result = cmd.ExecuteNonQuery();
                if (result > 0)
                {
                    MessageBox.Show("Update Success!!!", "Succesfull");
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error"); }
            conn.Close();
            h.RefreshEployeeTable();
        }