public System.Data.DataTable GetDataTable(string sql) { var dt = new DataTable(); db2.TableFill(sql, dt); return(dt); }
/// <summary> /// 此方法用于静态方法GetRowById()并填充自己,如无数据则销毁自身。 /// 不能用于其它方式调用 /// </summary> /// <param name="id"></param> /// <param name="dBase"></param> /// <returns></returns> protected R getRowById(int id, IBaseDataClass2 dBase) { if (dBase == null) { this.Dispose(); throw new NullReferenceException("数据库对像不能为空"); } if (this.PrimaryKey.Length != 1) { this.Dispose(); throw new Exception("表[" + this.TableName + "] 主键数量不等于1"); } string sql = "select * from [{0}] where {1}={2}"; if (dBase is IBaseDataSpecial && ((IBaseDataSpecial)dBase).FieldMask == Shotgun.Model.Filter.EM_Safe_Field_MASK.MySQLMode) { sql = "select * from `{0}` where {1}={2}"; } sql = string.Format(sql, this.TableName, this.PrimaryKey[0].ColumnName, id); try { dBase.TableFill(sql, this); } catch { this.Dispose(); throw; } if (this.Rows.Count == 0) { this.Dispose(); return(null); } return(this[0]); }
protected R getRowById(int id, IBaseDataClass2 dBase, string[] Fields) { if (dBase == null) { this.Dispose(); throw new NullReferenceException("数据库对像不能为空"); } Shotgun.Model.Filter.EM_Safe_Field_MASK fieldMask; if (dBase is IBaseDataSpecial && ((IBaseDataSpecial)dBase).FieldMask == Shotgun.Model.Filter.EM_Safe_Field_MASK.MySQLMode) { fieldMask = Shotgun.Model.Filter.EM_Safe_Field_MASK.MySQLMode; } else { fieldMask = Shotgun.Model.Filter.EM_Safe_Field_MASK.MsSQLMode; } ClearEmptyColume(this, Fields); if (this.PrimaryKey.Length != 1) { this.Dispose(); throw new Exception("表[" + this.TableName + "] 主键数量不等于1,或不包括在输出列中"); } string sql = string.Empty; if (Fields == null || Fields.Length != 0) { sql = "select * "; } else { if (fieldMask == Shotgun.Model.Filter.EM_Safe_Field_MASK.MySQLMode) { foreach (string f in Fields) { sql += ",`" + f + "`"; } } else { foreach (string f in Fields) { sql += ",[" + f + "]"; } } sql = "select " + sql.Substring(1); } if (fieldMask == Shotgun.Model.Filter.EM_Safe_Field_MASK.MySQLMode) { sql += string.Format(" from `{0}` where {1}={2}", this.TableName, this.PrimaryKey[0].ColumnName, id); } else { sql += string.Format(" from [{0}] where {1}={2}", this.TableName, this.PrimaryKey[0].ColumnName, id); } try { dBase.TableFill(sql, this); } catch { this.Dispose(); throw; } if (this.Rows.Count == 0) { this.Dispose(); return(null); } return(this[0]); }