Reputation: 7140
I am working on a small windows forms program that reads data from a local database, which I have created by following this guide.
I have populated these tables with data using the Designer in Visual Studio, and there is no ability (nor will there ever be) for the program to make changes to this database at run-time, as they represent static, known data -- I could get identical results if I hard-coded the instantiation of each corresponding table row object in a constructor somewhere.
When I have Visual Studio build my solution, it generates two files -- the .exe that opens the Form, and a .mdf file with the database tables.
Two related questions -- does it even make sense to use a database with this kind of read-only data? And if so, is there a way to combine the .MDF file into the .exe? Again, there is zero need to ever modify the data, so I wouldn't think that the fact that you can't modify .exes need prevent this.
Upvotes: 0
Views: 795
Reputation: 646
Yes you can do this. But first you need to construct your dataset. I would create your data in SQL or similar then export it to XML along with an XSD schema.
Then in Visual Studio, add a DataSet object to your project.
Then you can talk to the DataSet object and use the XSD and XML to populate it.
https://msdn.microsoft.com/en-us/library/atchhx4f(v=vs.110).aspx
To keep this all within the .EXE, embed your XML data into a Resource file, then access it via the Resources static class.
Upvotes: 1