Reputation: 467
Im trying to read SQL statement from .SQL files in a resource folder,
I have 2 .SQL files right now and it reads one correctly and the other returns a NullRefrenceException
Here is my calling of the sql files:
string sqlFailRecordNoMatch = EmbeddedResource.GetString("Resources.SQLScripts.RecordNumberFailQuery.sql");
Here is the GetString
method:
public static string GetString(System.Reflection.Assembly assembly, string name)
{
System.IO.StreamReader sr = EmbeddedResource.GetStream(assembly, name);
string data = sr.ReadToEnd();
sr.Close();
return data;
}
Upvotes: 1
Views: 876
Reputation: 45101
It would be much easier if you simply use the resource editor from Visual Studio:
Textfile
and give it the name about what this query will do
.txt
to .sql
Properties.Resources.MySqlStatement
Upvotes: 0
Reputation: 67898
The only reason you would get a NullReferenceException
on one vs. the other is:
Embedded Resource
. You can check that by clicking on the file in the Solution Explorer
and hitting F4.I suspect it's #1.
Upvotes: 3