>I am trying to created an automated create Stored Procedure routine in VB.Net, but the SQL code is a tad long and a pain to manually add into a string. Is there a way I can save the TSQL code as a Text file then embed the file into the VB.Net project/executable and then recall it? In other words, recall the embedded text file and dump it's contents into a string, then use that string in my Create Procedure routine...?
>
>Please help, thanks in advanced.
Ben,
Add your text file to the project and make sure the
Build Action = Embedded Resource.
The run the following code (might want to clean it up a little since it is pretty down and dirty):
string myString;
string myResource = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".MyTextFile.txt";
using (Stream myStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(myResource))
{
using (StreamReader myReader = new StreamReader(myStream))
{
myString = myReader.ReadToEnd();
}
}
MessageBox.Show(myString);
Note: If your file was added to a folder within your project you need to include the folder information in the resource string.
Hope this helps.
Einar
Semper ubi sub ubi.