static void Main(string[] args) { String sOutputFile = ""; String sInputFile = ""; String[] Fields = { }; String O; bool bEcho = false; foreach (String Param in args) { if (Param == "-d") { bEcho = true; } String[] Options = Param.ToLower().Split(':'); O = Options[0].ToUpper(); if (O == "-O") { sOutputFile = Options[1]; } if (O == "-I") { sInputFile = Options[1]; } if (O == "-FIELDS") { Fields = Options[1].Split(','); } } if ((sInputFile == "") || (sOutputFile == "") || Fields.Count() == 0) { Usage(); return; } ObjDataSet S; DataIO.Read(sInputFile, out S, true); ObjDataSet Extracted = DataIO.Extract(S, Fields); DataIO.Write(Extracted, sOutputFile); if (bEcho) { DataIO.Dump(Extracted); } }
//Export a data set from our SQL server query public bool ExecuteQuery(string SQLStatement, out ObjDataSet ResultDataSet) { if (conn.State == System.Data.ConnectionState.Open) { SqlCommand cmd = new SqlCommand(SQLStatement, conn); SqlDataReader dataReader; dataReader = cmd.ExecuteReader(); ObjDataRow Row; ObjDataSet Results = new ObjDataSet(); //Get the headers for (int i = 0; i < dataReader.FieldCount; i++) { Results.AddHeader(dataReader.GetName(i), dataReader.GetFieldType(i)); } //Store the data while (dataReader.Read()) { Object[] values = new Object[dataReader.FieldCount]; dataReader.GetValues(values); Row = new ObjDataRow(); Row.Add(values); Results.Add(Row); values = null; } dataReader.Close(); cmd.Dispose(); conn.Close(); ResultDataSet = Results; } else { Logging.Write("Tried to execute statement whilst not correct state, try later"); ResultDataSet = null; } return(false); }
static void Main(string[] args) { //Compare 2 CSV files //Output the differences (either removed or added) ObjDataSet A, B; bool TwoWay = false; String sFileOne = ""; String sFileTwo = ""; String[] OutputFile = new string[2]; bool Echo = false; String O; foreach (String Param in args) { String[] Options = Param.ToLower().Split(':'); if (Options.Count() == 2) { O = Options[0].ToUpper(); if (O == "-OUTPUT") { TwoWay = true; } else if (O == "-A") { sFileOne = Options[1]; } else if (O == "-B") { sFileTwo = Options[1]; } else if (O == "-OA") { OutputFile[0] = Options[1]; } else if (O == "-OB") { OutputFile[1] = Options[1]; } } if (Options.Count() == 1) { O = Options[0].ToUpper(); if (O == "-ONEWAY") { TwoWay = false; } else if (O == "-TWOWAY") { TwoWay = true; } else if (O == "-D") { Echo = true; } } } DataIO.Read(sFileOne, out A, true); DataIO.Read(sFileTwo, out B, true); //One way only ObjDataSet OutputA = DataIO.Diff(A, B, false); Console.WriteLine(sFileOne + " has " + OutputA.GetRowCount() + " additional records "); DataIO.Write(OutputA, OutputFile[0]); if (Echo) { DataIO.Dump(OutputA); } if (TwoWay) { ObjDataSet OutputB = DataIO.Diff(B, A, false); Console.WriteLine("\n" + sFileTwo + " has " + OutputB.GetRowCount() + " additional records "); DataIO.Write(OutputB, OutputFile[1]); if (Echo) { DataIO.Dump(OutputB); } } }