Esempio n. 1
0
        /// <summary>
        ///  执行语句,返回受影响的行数 ,select 语句不返回受影响行数
        /// </summary>
        private void ExecuteScalar()
        {
            object           obj  = null;
            String           xml  = XmlToSqlCmd_v2.getPostContent();
            List <XmlToList> list = XmlToSqlCmd_v2.ConvertXmlToSqlCommand(xml);

            foreach (XmlToList xtl in list)
            {
                try
                {
                    obj = DBHelper.DBExecuteScalar(xtl.SQL, xtl.PARS);
                }
                catch (SqlException exp)
                {
                    //exp.Message;
                    HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
                    HttpContext.Current.Response.ContentType     = "text/xml";
                    HttpContext.Current.Response.Write("<sqlerr><![CDATA[" + exp.Message + "]]></sqlerr>");
                    return;
                    //throw;
                }
            }

            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
            HttpContext.Current.Response.ContentType     = "text/xml";
            if (obj != null)
            {
                HttpContext.Current.Response.Write("<sqlresult><![CDATA[" + obj.ToString() + "]]></sqlresult>");
            }
        }
Esempio n. 2
0
        private void XmlToSqlExec2()
        {
            String           xml  = XmlToSqlCmd_v2.getPostContent();
            List <XmlToList> list = XmlToSqlCmd_v2.ConvertXmlToSqlCommand(xml);
            DataSet          ds   = new DataSet("data");

            foreach (XmlToList xtl in list)
            {
                try
                {
                    DataTable table = DBHelper.DataTableDBExecuteSqlCommand(xtl.SQL, xtl.PARS);
                    if (!String.IsNullOrEmpty(xtl.TABLENAME))
                    {
                        table.TableName = xtl.TABLENAME;
                    }
                    ds.Tables.Add(table);
                }
                catch (SqlException exp)
                {
                    //exp.Message;
                    HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
                    HttpContext.Current.Response.ContentType     = "text/xml";

                    HttpContext.Current.Response.Write("<sqlerr><![CDATA[" + exp.Message + "]]></sqlerr>");

                    return;
                    //throw;
                }
            }

            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
            HttpContext.Current.Response.ContentType     = "text/xml";

            string XmlSchema = ds.GetXmlSchema();
            string Xml       = ds.GetXml();

            HttpContext.Current.Response.Write(XmlSchema + "<xmlsplit></xmlsplit>" + Xml);
        }