• 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();
                            }
                        }
                    }

                }

            }
        }
    }
    做个快乐的自己。
  • 相关阅读:
    VC 中Combo Box的使用 Chars
    毕业论文摘要的书写方法和技巧 Chars
    VC调用DLL Chars
    《CLR via C#》Part1之Chapter3 共享程序集和强命名程序集(二)
    委托的使用(转)
    新概念系列之《Lesson 133 Sensational news》
    《CLR via C#》Part1之Chapter2 生成、打包、部署及管理应用程序及类型
    新概念系列之《Part2 Lesson 17 Always young》
    新概念系列之《Part2 Lesson 4 An exciting trip》
    新概念系列之《Part2 Lesson 16 A polite request》
  • 原文地址:https://www.cnblogs.com/Jessy/p/2048646.html
Copyright © 2020-2023  润新知