MyStringBuilder создание большой строки , например Insert для mysql

C Sharp > MyStringBuilder создание большой строки , например Insert для mysql
29.11.2012 13:51:51


Наиболее часто встречающиеся слова в статье:

[MyStringBuilder] ["delete] [jos_content] [catid=48]


Статья:

     internal bool SaveDatabaseTolocalFileMysql()
        {
            // работа  с файлом ,  запись туда инфо из базы
            bool result = true;
            string zapros;
            StreamWriter file;
            zapros = "SELECT name,[Описание],name from База_Решений";
            int tii2 = 0;
            string aliases = "";
            string zzz = "";
            string zzz2 = "";
            string stroka = "";
            string show_title = "show_title=link_titles=show_intro=show_section=link_section=show_category=link_category=show_vote=show_author=show_create_date=show_modify_date=show_pdf_icon=show_print_icon=show_email_icon=language=keyref=readmore=";
            DateTime curDatePlus1Day = DateTime.Now.Date;
            StringBuilder MyStringBuilder = new StringBuilder("--Start FILE \n");
            MyStringBuilder.Append("delete from jos_content where catid=48; \n");
            MyStringBuilder.Append("delete from jos_content where catid =''; \n");

            using (SqlConnection con = new SqlConnection(connectionstring))
            {


                SqlCommand com = new SqlCommand(zapros, con);
                try
                {
                    file = new StreamWriter(new FileStream("mysql.sql", FileMode.Create), Encoding.GetEncoding(1251));
                    con.Open();
                    SqlDataReader dr = com.ExecuteReader();
                
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            tii2 = tii2 + 1;
                            aliases = "CsharpADONET" + tii2.ToString();
                            zzz = dr.GetValue(1).ToString().Replace("'", "\\\'");
                            zzz = zzz.Replace("\r\n", "<br>");
                            zzz = zzz.Replace("\n", "<br>");
                            zzz = @zzz;
                            zzz2 = dr.GetValue(0).ToString().Replace("'", "\\\'");
                            zzz2 = @zzz2;
                            stroka = String.Format("insert into jos_content (title,alias,introtext,sectionid,catid,created,created_by,state,mask,checked_out,attribs,version,parentid,ordering,metakey) values ('{0}','{1}','{2}',4,48,'{3}',62,1,0,0,'{4}',1,0,1,'sql,tsql,C#'); ", zzz2, aliases, zzz, curDatePlus1Day, show_title);
                            MyStringBuilder.Append(stroka);
                            MyStringBuilder.Append(" \n ");
                        }
                    }
                    else { MyStringBuilder.Append("--NO LINES"); }

                    MyStringBuilder.Append("--END FILE");
                    file.WriteLine(MyStringBuilder);
                    result = true;
                    file.Dispose();

                }
                catch
                {
                   
                    result = false;
                }


            }
            return result;

        }