将xml导入到oracle库里

using System;

using System.ComponentModel;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

using Oracle.DataAccess.Client;

using System.Data;

using System.Xml;



namespace Mainfrm

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            this.But_InPutxml.Enabled = false;

        }

        /// <summary>

        /// 表名

        /// </summary>

        private string SQLTableName = "";

        private int SQLCount = 0;

        private string SQLCurrentFileName = "";

        //private string ConnectionString = "";

        private void But_Open_xml_Click(object sender, EventArgs e)

        {

            if (this.folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)

            {

                this.txt_Pirnt_Path.Text = this.folderBrowserDialog1.SelectedPath;

                this.But_InPutxml.Enabled = true;

            }

        }



        private void But_InPutxml_Click(object sender, EventArgs e)

        {

            //if (isvalue)

            //{

            //    MessageBox.Show("请填写数据库连接信息!");

            //    return;

            //}

            try

            {

               

                this.But_Open_xml.Enabled = false;

                this.But_InPutxml.Enabled = false;

                string SelectedPrintPath = this.txt_Pirnt_Path.Text;

                //string ConnectionString = "Data Source=zq103; User Id=jtcontrol; Password=jtcontrol";

                string ConnectionString = "Data Source=253; User Id=bzlscontrol; Password=bzlscontrol";



                OracleConnection conn = new OracleConnection(ConnectionString);

                if (conn.State != ConnectionState.Open)

                    conn.Open();







                string SQLINSERTPRINT = "";



                string content = "";

                ///打印模板ID

                string PrintID = "";

                ///打印模板名称

                string PrintTitle = "";

                ///打印模板参数

                string PrintParams = "";

                ///打印模板事件

                string PrintTemplateBody = "";

                string PrintItemid = "";

                string TEMPLATEDESC = "";

                string FORMMAINID = "";

                string[] dirinfo = Directory.GetFiles(SelectedPrintPath + "\\", "*.xml");

                this.Invoke(new MethodInvoker(delegate() {

                    this.lb_Add_Count.Text = (dirinfo.Length / 2).ToString(); 

                    this.lb_Add_Count.Refresh(); }));

                

                foreach (var v in dirinfo)

                {

                    if ("CONFIG.XML" == v.Substring(v.LastIndexOf(".") - 6).ToUpper())

                    {

                        SQLCount++;

                        SQLCurrentFileName = v.ToString();

                        XmlDocument doc = new XmlDocument();

                        doc.Load(v.ToString());

                        foreach (XmlElement el in doc.DocumentElement.ChildNodes)

                        {

                            if ("PRINTTEMPLATE" == el.Name.ToUpper())

                            {

                                foreach (XmlNode node in el.ChildNodes)

                                {

                                    if (node.Name.ToUpper() == "PRINTID")///id

                                    {

                                        PrintID = node.InnerText;

                                        continue;

                                    }

                                    if (node.Name.ToUpper() == "TEMPLATENAME")////name

                                    {

                                        PrintTitle = node.InnerText;

                                        continue;

                                    }

                                    if (node.Name.ToUpper() == "TEMPLATEBODY")///body

                                    {

                                        PrintTemplateBody = node.InnerText;

                                        continue;

                                    }

                                    if (node.Name.ToUpper() == "PARAMS")////params

                                    {

                                        PrintParams = node.InnerText;

                                        continue;

                                    }

                                    if (node.Name.ToUpper() == "ITEMID")////item

                                    {

                                        PrintItemid = node.InnerText;

                                        continue;

                                    }

                                    break;

                                }

                                break;

                            }

                        }

                        SQLINSERTPRINT = "insert into "

                            + SQLTableName + " (FORMMAINID, PRINTID, TEMPLATENAME, TEMPLATEDESC, PARAMS, ITEMID,TEMPLATEBODY) values ('"

                            + FORMMAINID + "','"

                            + PrintID + "','"

                            + PrintTitle + "','"

                            + TEMPLATEDESC + "','"

                            + PrintParams + "','"

                            + PrintItemid + "',:content)";

                        OracleCommand cmd = new OracleCommand(SQLINSERTPRINT, conn);

                        OracleParameter param = new OracleParameter(PrintTemplateBody, OracleDbType.Clob);

                        param.Value = PrintTemplateBody;

                        cmd.Parameters.Add(param);

                        cmd.ExecuteNonQuery();

                        this.Invoke(new MethodInvoker(delegate()

                        {

                            this.lb_Count.Text = SQLCount.ToString();

                            this.lb_FileName.Text = SQLCurrentFileName.Substring(SQLCurrentFileName.LastIndexOf("//") + 1);

                            this.lb_Count.Refresh();

                            this.lb_FileName.Refresh();

                        }));

                    }

              

                   

                }

                if (conn != null)

                {

                    conn.Close();

                    conn.Dispose();

                }

            }



            catch (Exception ex)

            {

                this.textBox1.Text = ex.Message;

                MessageBox.Show(ex.Message); }

        }

        private bool isvalue = false;

        private void But_Table_Click(object sender, EventArgs e)

        {

            if (this.txt_TableName.Text != "" || this.txt_Server.Text != "" || this.txt_User.Text != "" || this.txt_Pass.Text != "")

            {

                SQLTableName = this.txt_TableName.Text.Trim().ToString();

                this.txt_TableName.Enabled = false;

                this.But_Table.Enabled = false;

                isvalue = true;



                //ConnectionString = "Data Source=" + this.txt_Server.Text.Trim() + "; User Id=" + this.txt_User.Text.Trim() + "; Password=" + this.txt_Pass.Text;



            }

            else

            {

                MessageBox.Show("连接数据库服务信息不能为空!");

                isvalue = false;

            }



        }

    }

}

你可能感兴趣的:(oracle)