private string downloadMahasiswaTmp() { string err = string.Empty; try { cQuery qr = new cQuery(); cDatabase db = new cDatabase(); DataTable dt = null; dt = db.selectData(qr.qSelectMhs(), '2'); // '2' = ambil data dari 10.0.1.61 db s1makumyny4 if (dt.Rows.Count != 0) //jika ada data { //===inisialisasi progres bar====== if (ProgressBarSinkron.InvokeRequired) { ProgressBarSinkron.BeginInvoke( new Action(() => { ProgressBarSinkron.Value = 0; ProgressBarSinkron.Minimum = 0; ProgressBarSinkron.Maximum = dt.Rows.Count; } )); } //================================= cKoneksi koneksi = new cKoneksi(); using (var conn = new SQLiteConnection(koneksi.LokasiSqlite()))//koneksi ke sqlite { try { conn.Open();//buka koneksi using (var cmd = new SQLiteCommand(conn)) { using (var transaction = conn.BeginTransaction()) { //looping insert foreach (DataRow row in dt.Rows) { cmd.CommandText = qr.qInsertPenggunaTmp();//"insert into penggunaTmp (id,nik,nama,rfid,kategori) values (@id,@nik,@nama,@rfid,@kategori)"; cmd.Parameters.Clear(); cmd.Prepare(); cmd.Parameters.AddWithValue("@id", row["StudentID"]); //kenapa ID diisi sama kayak nik?? cmd.Parameters.AddWithValue("@nik", row["StudentID"]); //kenapa ID diisi sama kayak nik?? cmd.Parameters.AddWithValue("@nama", row["fullname"]); cmd.Parameters.AddWithValue("@rfid", row["rfid"]); cmd.Parameters.AddWithValue("@kategori", 1); // 1 = kategori mahasiswa cmd.ExecuteNonQuery(); //===proses progres bar====== if (ProgressBarSinkron.InvokeRequired) { ProgressBarSinkron.BeginInvoke( new Action(() => { ProgressBarSinkron.Increment(1); } )); } //=========================== } transaction.Commit(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); //tutup koneksi conn.Dispose(); } } ////===tutup progres bar====== //if (ProgressBarSinkron.Value == ProgressBarSinkron.Maximum)//jika sudah selesai tampilkan download complete //{ LblProgressBar.Text = "Download Complete"; } //MessageBox.Show("" + ProgressBarSinkron.Value + " Data Berhasil di Download"); //panelProgressBar.Visible = false;// hiden panel progressbar ////========================== } //clear datatable dt.Clear(); dt.Dispose(); //================ } catch (Exception ex) { err = ex.Message; //ProgressBarSinkron.Visible = false; MessageBox.Show(ex.Message); } return(err); }