void UpdateRecord() { //chech output type before update records if (rdgOut.SelectedIndex == -1) { Common.setEmptyField("Output Type", Program.ApplicationName); rdgOut.Focus(); return; } else { DataTable Dtt = new DataTable("ViewReport"); Dtt.BeginInit(); Dtt.Columns.Add("PlateRange"); Dtt.Columns.Add("RefNum"); Dtt.Columns.Add("PlateType"); Dtt.Columns.Add("DateIssued"); Dtt.Columns.Add("BatchCode"); Dtt.EndInit(); for (int i = 0; i < listView1.Items.Count; i++) { Dtt.Rows.Add(new object[] { listView1.Items[i].Text, txtRef.Text.Trim(), listView1.Items[i].SubItems[2].Text, dtpIssued.Value.Date.ToString("yyyy-MM-dd"), EncDec.EncryptString(listView1.Items[i].Text, "12345") }); } DataSet Ds = new DataSet("Issues"); Ds.Tables.Add(Dtt); //Ds.WriteXmlSchema(@"C:/Issues.xml"); //update records here using (SqlConnection db = new SqlConnection(Logic.ConnectionString)) { SqlTransaction transaction; db.Open(); transaction = db.BeginTransaction(); try { ////update plate stock record foreach (Object item in arrDataList)//get item from arraylist { if (item == null) { continue; } DataTable lol = item as DataTable; foreach (DataRow Dr in lol.Rows) { //object plate = Dr[0]; using (SqlCommand sqlCommand1 = new SqlCommand(String.Format(String.Format("UPDATE [tblMLVPlateStock] SET [Issued]='{{0}}',[IssuedRef]='{{1}}',[IssuedDate]='{{2}}',[MLOID]='{{3}}' where [PlateNo] ='{0}' ", Dr[0]), true, txtRef.Text.Trim(), dtpIssued.Value.Date.ToString("yyyy-MM-dd hh:mm:ss"), cboOffices.SelectedValue), db, transaction)) { sqlCommand1.ExecuteNonQuery(); } } } ////insert into issued history records for (int i = 0; i < listView1.Items.Count; i++) { using (SqlCommand sqlCommand = new SqlCommand(String.Format("INSERT INTO [tblIssuedHistory]([RefNumber],[Range],[MLOID],[PlateType])VALUES ('{0}','{1}','{2}','{3}');", txtRef.Text.Trim(), listView1.Items[i].Text, cboOffices.SelectedValue, listView1.Items[i].SubItems[2].Text), db, transaction)) { sqlCommand.ExecuteNonQuery(); } } transaction.Commit(); } catch (SqlException sqlError) { transaction.Rollback(); } db.Close(); } //print issued Report if (rdgOut.SelectedIndex == 1) { RepIssued report = new RepIssued { DataSource = Ds }; report.ShowPreviewDialog(); } else { string str = MosesClassLibrary.Serialization.Serialization.SerializeObjectToXML(Dtt); // object lop = MosesClassLibrary.Serialization.Serialization.DeserializeXMLToObject(str, new DataTable(). //GetType()); // DataTable dty = lop as DataTable; export(EncDec.EncryptString(str, "12345")); } } Common.setMessageBox(String.Format("Plate Number Issued to {0} Motor License Office", cboOffices.Text), Program.ApplicationName, 1); tsbReload.PerformClick(); }