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

            }

        }
    }
}
做个快乐的自己。
原文地址:https://www.cnblogs.com/Jessy/p/2048646.html