public List <SubResults> GetData(string TableName, string Data2Get, string Where = "") { List <SubResults> Results = new List <SubResults>(); SubResults _Subresult; SqlCommand MyCmd = this.MyConn.CreateCommand(); if (Where.Equals("")) { MyCmd.CommandText = "Select " + Data2Get + " from " + TableName; } else { MyCmd.CommandText = "Select " + Data2Get + " from " + TableName + " where " + Where; } try { MyReader = MyCmd.ExecuteReader(); while (MyReader.Read()) { _Subresult = new SubResults(); for (int i = 0; i < MyReader.FieldCount; i++) { _Subresult.Add(MyReader.GetValue(i)); } Results.Add(_Subresult); } MyReader.Close(); } catch (Exception MyEx) { Err(this, new IErrorEventArgs(MyEx, "GetData function in " + TableName + " on " + this.Database)); if (MyReader != null) { MyReader.Close(); } } return(Results); }
public SubResults Get1Data(string TableName, string Data2Get, string Where = "") { SubResults _Subresult = new SubResults(); SqlCommand MyCmd = this.MyConn.CreateCommand(); if (Where.Equals("")) { MyCmd.CommandText = "Select TOP 1 " + Data2Get + " from " + TableName; } else { MyCmd.CommandText = "Select TOP 1 " + Data2Get + " from " + TableName + " where " + Where; } try { MyReader = MyCmd.ExecuteReader(); while (MyReader.Read()) { for (int i = 0; i < MyReader.FieldCount; i++) { _Subresult.Add(MyReader.GetValue(i)); } } MyReader.Close(); } catch { if (MyReader != null) { MyReader.Close(); } } return(_Subresult); }
public List <SubResults> Get_TblFields(string TableName) { List <SubResults> Results = new List <SubResults>(); SubResults _Subresult; SqlCommand MyCmd = MyConn.CreateCommand(); MyCmd.CommandText = "Select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='" + TableName + "'"; try { MyReader = MyCmd.ExecuteReader(); while (MyReader.Read()) { _Subresult = new SubResults(); for (int i = 0; i < MyReader.FieldCount; i++) { _Subresult.Add(MyReader.GetValue(i)); } Results.Add(_Subresult); } MyReader.Close(); } catch (Exception MyEx) { Err(this, new IErrorEventArgs(MyEx, "Get_TblFields function with " + TableName + " on " + this.Database)); if (MyReader != null) { MyReader.Close(); } } return(Results); }