예제 #1
0
        public string insertPegawai(PegawaiInfo data)
        {
            Koneksi       kon    = new Koneksi();
            SqlConnection sqlcon = kon.getConnection();
            string        msg    = string.Empty;

            using (sqlcon)
            {
                sqlcon.Open();
                string     sql    = "insert pegawai values(@id, @nama, @alamat, @jk, @telepon)";
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                using (sqlcom)
                {
                    sqlcom.Parameters.AddWithValue("@id", data.IDPegawai);
                    sqlcom.Parameters.AddWithValue("@nama", data.NamaPegawai);
                    sqlcom.Parameters.AddWithValue("@alamat", data.alamatPegawai);
                    sqlcom.Parameters.AddWithValue("@jk", data.jeniskelaminPegawai);
                    sqlcom.Parameters.AddWithValue("@telepon", data.teleponPegawai);
                    int res = sqlcom.ExecuteNonQuery();
                    msg = (res != 0 ? "Data has been saved." : "Oops, something went wrong.");
                }
                sqlcon.Close();
            }
            return(msg);
        }
예제 #2
0
        public string updatePegawai(PegawaiInfo data)
        {
            Koneksi       kon    = new Koneksi();
            SqlConnection sqlcon = kon.getConnection();
            string        msg    = string.Empty;

            using (sqlcon)
            {
                sqlcon.Open();
                string     sql    = "update pegawai set nama = @nama, alamat = @alamat, jk = @jk, telepon = @telepon where idpegawai = @id";
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                using (sqlcom)
                {
                    sqlcom.Parameters.AddWithValue("@id", data.IDPegawai);
                    sqlcom.Parameters.AddWithValue("@nama", data.NamaPegawai);
                    sqlcom.Parameters.AddWithValue("@alamat", data.alamatPegawai);
                    sqlcom.Parameters.AddWithValue("@jk", data.jeniskelaminPegawai);
                    sqlcom.Parameters.AddWithValue("@telepon", data.teleponPegawai);
                    int res = sqlcom.ExecuteNonQuery();
                    msg = (res != 0 ? "Data has been updated." : "Oops, something went wrong.");
                }
                sqlcon.Close();
            }
            return(msg);
        }
예제 #3
0
        public List <PegawaiInfo> getPegawaiInfo()
        {
            // kode get data from sql server..
            Koneksi            kon     = new Koneksi();
            SqlConnection      sqlcon  = kon.getConnection();
            List <PegawaiInfo> objList = new List <PegawaiInfo>();

            using (sqlcon)
            {
                sqlcon.Open();
                string     sql    = "select * from pegawai";
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                using (sqlcom)
                {
                    SqlDataReader dr = sqlcom.ExecuteReader();
                    while (dr.Read())
                    {
                        PegawaiInfo obj = new PegawaiInfo();
                        obj.IDPegawai           = dr.GetString(0);
                        obj.NamaPegawai         = dr.GetString(1);
                        obj.alamatPegawai       = dr.GetString(2);
                        obj.jeniskelaminPegawai = dr.GetString(3);
                        obj.teleponPegawai      = dr.GetString(4);
                        objList.Add(obj);
                    }
                }
                sqlcon.Close();
            }
            return(objList);
        }