Thursday, January 9, 2014

Get embedded SQL Script at runtime

Prereqs
using System.IO;
using System.Reflection;

A sql script called Query.sql embedded in project ER. Embed the sql script by changing the Build Action = Embedded Resource

This loads an embedded sql script and outputs it to a textbox
using System.IO;
using System.Reflection;

            Assembly asm = Assembly.GetExecutingAssembly();
            StreamReader reader = new StreamReader(asm.GetManifestResourceStream("ER.Query.sql"));
            txtOutput.Text = reader.ReadToEnd();    
            reader.Close();

This can clearly be used for better purposes, such as executing the script.


Reference
Embedding resources in .NET: http://msdn.microsoft.com/en-us/magazine/cc163609.aspx


No comments:

Post a Comment

There was an error in this gadget