public static bool insertUsers(AdminSectionEntity ce) { bool flag = false; using (SqlConnection conn = new SqlConnection(Connection.getConnectionString())) { using (SqlCommand cmd = new SqlCommand("insertUsers", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@usernm", ce.userName); cmd.Parameters.AddWithValue("@pwd", ce.password); cmd.Parameters.AddWithValue("@roleid", ce.userRole); conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { dr.Read(); flag = (bool)dr[0]; } return(flag); } } }
private void Ok_button_Click(object sender, EventArgs e) { if (Valid()) { AdminSectionEntity ce = new AdminSectionEntity() { userName = username_TextBox.Text, password = password_TextBox.Text, userRole = int.Parse(userRole_comboBox.SelectedValue.ToString()) }; bool isNotExists = AdminSection_Methods.insertUsers(ce); if (isNotExists) { AlertBox.ShowDialog("UserName is already Exists.", AlertBox.AlertType.error, false); } else { AlertBox.ShowDialog("User Created", AlertBox.AlertType.success, true); } } }