Thursday, January 9, 2014

Get embedded SQL Script at runtime

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

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

Embedding resources in .NET:

No comments:

Post a Comment

There was an error in this gadget