Пример #1
0
        public void Write(XMLmodel model, string dbname, string tablename, string dirpath, string prefix = "")
        {
            string filename = dirpath + @"\" + "Data_" + prefix + "_" + dbname + "_" + tablename + ".xml";

            //File.Create(filename);
            GenerateFile(model, filename);
        }
Пример #2
0
        private void GenerateFile(XMLmodel data, string filepath)
        {
            XmlTextWriter writer = new XmlTextWriter(filepath, System.Text.Encoding.UTF8);

            writer.WriteStartDocument(true);
            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartElement("Data");
            createNode(writer, data);
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
        }
Пример #3
0
 private void createNode(XmlTextWriter writer, XMLmodel data)
 {
     foreach (var rows in data.Data)
     {
         writer.WriteStartElement("row");
         for (int i = 0; i < rows.Count; i++)
         {
             writer.WriteStartElement(data.Columnname[i]);
             writer.WriteString(rows[i]);
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
 }
Пример #4
0
        public XMLmodel Getdata(string tablename, string dbname, string connectionstring)
        {
            _dbname    = dbname;
            _tableName = tablename;
            _conStr    = connectionstring;
            XMLmodel datamodel = new XMLmodel();

            datamodel.tablename = tablename;

            IEnumerable <string> col = GetColumnNames();

            GetTableData(col, datamodel);
            return(datamodel);
        }
Пример #5
0
        public void Setup(string dbname, string dirpath, string connectionstring, string prefix = "")
        {
            GetalltheTable tableobj   = new GetalltheTable();
            List <string>  tablesList = tableobj.GettableList(connectionstring, dbname);
            Createtable    ct         = new Createtable();

            ct.Write(dbname, dirpath, connectionstring, prefix);
            foreach (var table in tablesList)
            {
                GetTheDataFromTable dtDataFromTable = new GetTheDataFromTable();
                XMLmodel            model           = dtDataFromTable.Getdata(table, dbname, connectionstring);
                XMLWriter           wrobj           = new XMLWriter();
                wrobj.Write(model, dbname, table, dirpath, prefix);
            }
        }
Пример #6
0
        private void GetTableData(IEnumerable <string> col, XMLmodel datamodel)
        {
            var    result = new List <string>();
            string column = "";

            string conString = _conStr;

            using (SqlConnection con = new SqlConnection(conString))
            {
                con.Open();

                // Set up a command with the given query and associate
                // this with the current connection.
                using (SqlCommand cmd = new SqlCommand("use " + _dbname + ";SELECT top 5  * from " + _tableName, con))
                {
                    try
                    {
                        using (IDataReader dr = cmd.ExecuteReader())
                        {
                            for (int i = 0; i < col.Count(); i++)
                            {
                                column = Convert.ToString(col.ElementAt(i));
                                datamodel.Columnname.Add(column);
                            }
                            while (dr.Read())
                            {
                                List <string> data = new List <string>();
                                for (int i = 0; i < col.Count(); i++)
                                {
                                    // column = ","+column + Convert.ToString(col.ElementAt(i));
                                    data.Add(Convert.ToString(dr[datamodel.Columnname[i]]));
                                }
                                datamodel.Data.Add(data);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //   throw;
                    }
                }
            }
        }