コード例 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dtKaryawan.CurrentCell.RowIndex > -1)
            {
                try
                {
                    string[] baru = new string[4];
                    using (SqlConnection myConnection = new SqlConnection())
                    {
                        string     oString = "SELECT * FROM karyawan WHERE NIK = @NIK";
                        SqlCommand oCmd    = new SqlCommand(oString, myConnection);
                        oCmd.Parameters.Add("@NIK", SqlDbType.VarChar).Value = dtKaryawan.Rows[dtKaryawan.CurrentCell.RowIndex].Cells[0].Value;
                        myConnection.ConnectionString = @"Data Source=" + Properties.Settings.Default.Server + "; Initial Catalog=" + Properties.Settings.Default.DBName + "; Integrated Security=True";
                        myConnection.Open();
                        using (SqlDataReader oReader = oCmd.ExecuteReader())
                        {
                            while (oReader.Read())
                            {
                                baru[0] = oReader["NIK"].ToString();
                                baru[1] = oReader["nama"].ToString();
                                baru[2] = oReader["alamat"].ToString();
                                baru[3] = oReader["instansi"].ToString();
                            }

                            myConnection.Close();
                        }
                    }
                    frm = new frmFormulirKaryawan(this, baru[0], baru[1], baru[2], baru[3]);
                    frm.ShowDialog(this);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "ERR: " + ex.ToString());
                }
            }
            else
            {
                MessageBox.Show(this, "Pilih karyawan yang akan Anda ubah!", "Exist", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #2
0
 private void button3_Click(object sender, EventArgs e)
 {
     frm = new frmFormulirKaryawan(this);
     frm.ShowDialog(this);
 }