private void insertButton_Click(object sender, RoutedEventArgs e) { int i = 0; string datas = ""; try { foreach (DataRow row in values.Rows) { if (i == 0) { datas = "('" + row[0].ToString() + "','" + row[1].ToString() + "','" + row[2].ToString() + "','" + row[3].ToString() + "','" + Convert.ToDateTime(row[4].ToString()).ToString("yyyy-MM-dd HH:mm:ss") + "','" + row[5].ToString() + "','" + row[6].ToString() + "','" + row[7].ToString() + "','" + row[8].ToString() + "','" + row[9].ToString() + "','" + row[10].ToString() + "')"; } else { datas = datas + ",('" + row[0].ToString() + "','" + row[1].ToString() + "','" + row[2].ToString() + "','" + row[3].ToString() + "','" + Convert.ToDateTime(row[4].ToString()).ToString("yyyy-MM-dd HH:mm:ss") + "','" + row[5].ToString() + "','" + row[6].ToString() + "','" + row[7].ToString() + "','" + row[8].ToString() + "','" + row[9].ToString() + "','" + row[10].ToString() + "')"; } i++; } string res = DBManager.InsertIntoAllocationRequestes(datas); if (!res.Contains("Success")) { myMessageBox mm = new myMessageBox("Invalid Data Type Found. Check your data again", "Error", "OK", 1); mm.ShowDialog(); // MessageBox.Show("Invalid Data Type Found. Check your data again", "Error Occured", MessageBoxButton.OK, MessageBoxImage.Error); } else { myMessageBox mm = new myMessageBox("Data added successfully.", "Success", "OK", 0); mm.ShowDialog(); // MessageBox.Show("Data Added Succesfully", "Successfully Added", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } catch (Exception ex) { // } }