zoukankan      html  css  js  c++  java
  • Loads the specified manifest resource from this assembly

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Reflection;

    using System.Data.SqlClient;

    namespace ConsoleApplication3
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
            }

            
    // Loads the specified manifest resource from this assembly.
            
    // fileName: createLgin.Sql
            private void test(string ConnectionString, string fileName)
            {
                
    using (SqlConnection conn = new SqlConnection(ConnectionString))
                {

                    Assembly assem 
    = this.GetType().Assembly;

                    
    using (Stream stream = assem.GetManifestResourceStream(this.GetType().Namespace + "fileName"))
                    {
                        
    using (StreamReader reader = new StreamReader(stream))
                        {
                            
    string line = reader.ReadLine();
                            StringBuilder lBuild 
    = new StringBuilder();
                            
    while (null != line)
                            {

                                
    // Not "safe" to do this in general, but works for this embedded file
                                
    //
                                if (!line.StartsWith("GO", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    lBuild.Append(line);
                                    lBuild.AppendLine();
                                }
                                
    else
                                {
                                    
    string loginCommand = lBuild.ToString();
                                    SqlCommand loginCmd 
    = new SqlCommand(loginCommand, conn);
                                    loginCmd.ExecuteNonQuery();
                                    lBuild 
    = lBuild.Remove(0, lBuild.Length);
                                }
                                line 
    = reader.ReadLine();
                            }
                        }
                    }

                }

            }
        }
    }
    做个快乐的自己。
  • 相关阅读:
    python使用pip离线安装库
    centos 6.5 ftp服务配置及客户端使用
    centos7 ntp服务器配置
    Python:如何排序(sort)
    python报OperationalError: (1366, "Incorrect string value..."的问题解决
    使用matplotlib画双纵轴坐标
    python安装PIL库
    【干货分享】前端面试知识点锦集04(Others篇)——附答案
    【干货分享】前端面试知识点锦集03(JavaScript篇)——附答案
    【干货分享】前端面试知识点锦集02(CSS篇)——附答案
  • 原文地址:https://www.cnblogs.com/Jessy/p/2048646.html
Copyright © 2011-2022 走看看