public override DataTable GetDataTable(string Sql) { try { SqlLogger.WriteSql(Sql); MySqlDataAdapter adapter = new MySqlDataAdapter(Sql, conn); DataSet ds = new DataSet(); conn.Open(); ds.EnforceConstraints = false; adapter.FillSchema(ds, SchemaType.Source, "table"); adapter.Fill(ds, "table"); conn.Close(); return(ds.Tables[0]); } catch (Exception ex) { throw ex; } finally { conn.Close(); } }
public override object ExecuteDataReader(string Sql) { SqlLogger.WriteSql(Sql); MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = Sql; conn.Open(); //cmd.ExecuteNonQuery(); return(cmd.ExecuteReader()); }
public override object Execute(string Sql) { Object lastInsertID = null; try { if (Sql != "") { SqlLogger.WriteSql(Sql); MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = Sql; cmd.CommandTimeout = (this.CommandTimeOut != -1) ? this.CommandTimeOut : cmd.CommandTimeout; conn.Open(); //cmd.ExecuteNonQuery(); lastInsertID = cmd.ExecuteScalar(); conn.Close(); } } catch (Exception ex) { if (ex.Message.Contains("foreign key constraint fails")) { throw new Exception("Kan niet verwijderen, want er zijn nog gerelateerde gegevens.", ex); } else if (ex.Message.Contains("Duplicate entry")) { throw new Exception("Kan niet opslaan, want een gegeven is niet uniek. Zie de volgende melding: " + ex.Message, ex); } throw ex; } finally { conn.Close(); } if (lastInsertID != null && lastInsertID.ToString() == String.Empty) { lastInsertID = 0; } return(lastInsertID); }