コード例 #1
0
        public static void RunResultsetToDataTableTest(MainForm frm, PFSQLServerCE40 db)
        {
            SqlCeResultSet res   = null;
            string         query = string.Empty;

            _msg.Length = 0;
            _msg.Append("Running RunResultsetToDataTableTest ...");
            Program._messageLog.WriteLine(_msg.ToString());

            try
            {
                query = frm.txtQuery.Text;
                db.OpenConnection();
                res = db.RunQueryResultset(query);

                if (res.HasRows)
                {
                    DataTable tab = PFSQLServerCE40.ConvertResultSetToDataTable(res);

                    _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());
                    }
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("No rows in resultset");
                    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("...RunResultsetToDataTableTest Finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #2
0
        public static void RunResultsetTest(MainForm frm, PFSQLServerCE40 db)
        {
            SqlCeResultSet res   = null;
            string         query = string.Empty;

            _msg.Length = 0;
            _msg.Append("Running RunResultsetTest ...");
            Program._messageLog.WriteLine(_msg.ToString());

            try
            {
                query = frm.txtQuery.Text;
                db.OpenConnection();
                res = db.RunQueryResultset(query);
                if (res.HasRows)
                {
                    db.returnResult += new PFSQLServerCE40.ResultDelegate(OutputResults);
                    //sqlce.returnResultAsString += new PFSQLServerCE40.ResultAsStringDelegate(OutputResultsAsString);
                    db.ProcessResultSet(res);
                    res.Close();
                    res = db.RunQueryResultset(query);
                    db.returnResultAsString += new PFSQLServerCE40.ResultAsStringDelegate(OutputExtractFormattedData);
                    db.ExtractDelimitedDataFromResultSet(res, "\t", "\r\n", true);
                    res.Close();

                    res = db.RunQueryResultset(query);
                    db.SaveResultSetToXmlFile(res, @"c:\temp\TestCeRes.xml");
                    res.Close();

                    res = db.RunQueryResultset(query);
                    db.SaveResultSetWithSchemaToXmlFile(res, @"c:\temp\TestCeResPlus.xml");
                    res.Close();

                    res = db.RunQueryResultset(query);
                    db.SaveResultSetToXmlSchemaFile(res, @"c:\temp\TestCeRes.xsd");
                    res.Close();

                    res = db.RunQueryResultset(query);
                    PFDataProcessor dataProcessor = new PFDataProcessor();
                    XmlDocument     xmlDoc        = dataProcessor.CopyDataTableToXmlDocument(PFSQLServerCE40.ConvertResultSetToDataTable(res, "ResultTable"));
                    Program._messageLog.WriteLine("\r\n" + xmlDoc.OuterXml + "\r\n");
                    res.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("...RunResultsetTest Finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }