public void UpdateTable(TableFramework FrameWork, string whereText) { if (FrameWork.TableName == null) FrameWork.TableName = TableName; if (FrameWork.TableName == null) throw new Exception("No Found TableName Attribute!"); string sql = "update [" + FrameWork.TableName + "] set"; string setText = ""; foreach (TableFramework.Column col in FrameWork) { if (setText != "") { setText += ","; } setText += "[" + col.Name + "]="; if (col.CType == typeof(int) || col.CType == typeof(double) || col.CType == typeof(long) || col.CType == typeof(short) || col.CType == typeof(float) || col.CType == typeof(decimal) || col.CType == typeof(long)) { setText += col.Value; } else if (col.CType == typeof(string)) { setText += "'" + SafeText(col.Value.ToString()) + "'"; } else if (col.CType == typeof(DateTime)) { setText += "#" + col.Value + "#"; } else if (col.CType == typeof(bool)) { setText += col.Value.ToString(); } else { throw new Exception("I dont' no " + col.CType.Name + " is Nothign!"); } } if (setText == "") throw new Exception("Table's FrameWork is not Empty!"); sql += setText + " " + whereText; Command.CommandText = sql; Command.ExecuteNonQuery(); }
public void InsertTable(TableFramework FrameWork) { if (FrameWork.TableName == null) FrameWork.TableName = TableName; if (FrameWork.TableName == null) throw new Exception("No Found TableName Attribute!"); string sql = "insert into [" + FrameWork.TableName + "]("; string Names = ""; string Values = ""; foreach (TableFramework.Column col in FrameWork) { if (Names != "") { Names += ","; Values += ","; } Names += "[" + col.Name + "]"; if (col.CType == typeof(int) || col.CType == typeof(double) || col.CType == typeof(long) || col.CType == typeof(short) || col.CType == typeof(float) || col.CType == typeof(decimal)) { Values += col.Value; } else if (col.CType == typeof(string)) { Values += "'" + SafeText(col.Value.ToString()) + "'"; } else if (col.CType == typeof(DateTime)) { Values += "#" + col.Value + "#"; } else if (col.CType == typeof(bool)) { Values += col.Value.ToString(); } else { throw new Exception("I dont' know" + col.CType.Name + " is Nothign!"); } } if (Names == "") throw new Exception("Table's FrameWork is not Empty!"); sql += Names + ")values(" + Values + ")"; Command.CommandText = sql; Command.ExecuteNonQuery(); }