public static void RunReaderTest(MainForm frm, PFSQLServerCE40 db) { string query = string.Empty; _msg.Length = 0; _msg.Append("Running RunReaderTest ..."); Program._messageLog.WriteLine(_msg.ToString()); try { query = frm.txtQuery.Text; db.OpenConnection(); SqlCeDataReader rdr = (SqlCeDataReader)db.RunQueryDataReader(query); db.returnResult += new PFSQLServerCE40.ResultDelegate(OutputResults); //sqlce.returnResultAsString += new PFSQLServerCE40.ResultAsStringDelegate(OutputResultsAsString); db.ProcessDataReader(rdr); rdr.Close(); rdr = (SqlCeDataReader)db.RunQueryDataReader(query); db.SaveDataReaderToXmlFile(rdr, @"c:\temp\TestCeRdr.xml"); rdr.Close(); rdr = (SqlCeDataReader)db.RunQueryDataReader(query); db.SaveDataReaderWithSchemaToXmlFile(rdr, @"c:\temp\TestCeRdrPlus.xml"); rdr.Close(); rdr = (SqlCeDataReader)db.RunQueryDataReader(query); db.SaveDataReaderToXmlSchemaFile(rdr, @"c:\temp\TestCeRdr.xsd"); rdr.Close(); rdr = (SqlCeDataReader)db.RunQueryDataReader(query); PFDataProcessor dataProcessor = new PFDataProcessor(); XmlDocument xmlDoc = dataProcessor.CopyDataTableToXmlDocument(db.ConvertDataReaderToDataTable(rdr)); Program._messageLog.WriteLine("\r\n" + xmlDoc.OuterXml + "\r\n"); rdr.Close(); db.CloseConnection(); } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); Program._messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { _msg.Length = 0; _msg.Append("...RunReaderTest Finished."); Program._messageLog.WriteLine(_msg.ToString()); } }
public static void RunReaderToDataTableTest(MainForm frm, PFSQLServerCE40 db) { string query = string.Empty; _msg.Length = 0; _msg.Append("Running RunReaderToDataTableTest ..."); Program._messageLog.WriteLine(_msg.ToString()); try { query = frm.txtQuery.Text; db.OpenConnection(); SqlCeDataReader rdr = (SqlCeDataReader)db.RunQueryDataReader(query); DataTable tab = db.ConvertDataReaderToDataTable(rdr); _msg.Length = 0; _msg.Append("Number of rows in table: "); _msg.Append(tab.Rows.Count); Program._messageLog.WriteLine(_msg.ToString()); int inx = 0; int maxInx = tab.Rows.Count - 1; int inxCol = 0; int maxInxCol = tab.Columns.Count - 1; for (inx = 0; inx <= maxInx; inx++) { _msg.Length = 0; DataRow row = tab.Rows[inx]; for (inxCol = 0; inxCol <= maxInxCol; inxCol++) { DataColumn col = tab.Columns[inxCol]; _msg.Append(col.ColumnName); _msg.Append(": "); _msg.Append(row[inxCol].ToString()); if (inxCol < maxInxCol) { _msg.Append(", "); } } Program._messageLog.WriteLine(_msg.ToString()); } db.CloseConnection(); } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); Program._messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { _msg.Length = 0; _msg.Append("...RunReaderToDataTableTest Finished."); Program._messageLog.WriteLine(_msg.ToString()); } }