如何使用Query的结果在DataSet中添加行

时间:2017-03-31 13:45:32

标签: xml dataset

public bool ReadDataSetOnStartUp(string sqlQuery,string xsdPath)
        {
        bool result = false;

        try
        {
            if (!ValidateQueryWithXSDParameters(sqlQuery,xsdPath))
            {
                this.tracer.TraceError(string.Format("[ReadDataSetOnStartUp]::Query has some invalid parameters ignoring the Query."));
            }               

            DataSet dsFromXSD = new DataSet();
            dsFromXSD.ReadXmlSchema(xsdPath);
            var dataSet = this.databaseAccess.ExecuteQueryWithNoCallBack(sqlQuery, GetAllTableMappings(dsFromXSD));

            if (dataSet != null)
            {
                dsFromXSD.WriteXmlSchema(@"..\..\config\GetPred.xsd");                    
                dsFromXSD.Merge(dataSet, true, MissingSchemaAction.Ignore);
                dsFromXSD.AcceptChanges();                    
                dsFromXSD.WriteXml(@"..\..\config\GetPred.xml");

                dsFromXSD.Tables["GetPredictionResult"].Rows.Add(DateTime.Now, true, Environment.MachineName, dsFromXSD);

                if (dataSet.Tables != null && dataSet.Tables.Count > 0)
                {
                    //Success in the query - Write to XML
                    this.tracer.TraceDebug(string.Format("[ReadDataSetOnStartUp] - Success in query execution"));
                    selectedTables = dataSet.Tables[0];

                    if (selectedTables != null && selectedTables.Rows.Count > 0)
                    {
                        this.tracer.TraceDebug(string.Format("[ReadDataSetOnStartUp]::Successfully Read the query."));
                    }
                }                    
            }
            else
            {
                this.tracer.TraceDebug(string.Format("[ReadDataSetOnStartUp]::No Events are available currently as Data Set is empty."));
            }

            result = true;               
        }
        catch (Exception ex)
        {
            this.tracer.TraceError(  string.Format( "[ReadDataSetOnStartUp]::Exception Encountered while Reading and registering query callback: {0}",ex.Message));
            result = false; 
        }

        this.tracer.TraceDebug( string.Format("[ReadDataSetOnStartUp] EXIT."));

        return result;
    }

到目前为止,我得到一个例外说法:

  

ex.Message ="无法转换类型' System.Data.DataSet'至   键入' System.IConvertible'。不能存储   GetPredictionResult_Id专栏。预期的类型是Int32。"

0 个答案:

没有答案