During the demonstration of layer-3 architecture development for my students, I used winform in vs2005 to establish the Dal, BLL, and uilayer-3 architectures, and used strong datasets in the Dal layer, bll layer processing logic. ProgramAfter running, the update, insert, delete, and other operations on the tableadapter take effect. Then I observe the MDF file and the data is not updated. when winform is disabled and winform is restarted, it is found that the modification only affects strong datasets, but the datasets are not eventually reflected in the MDF file. the Return Value of the tableadapter method call indicates that my method is successful!
Environment:
1. Create the app_data directory under the project, place the MDF file, and double-click the MDF file to mount the MDF to sqlserver express using attachdbfilename;
2. Add a new dataset, drag the table in 1 to dataset to generate a strong dataset, and then build the tableadapter method set and BLL layer of the Dal layer to complete the system.
Debugging found that every time I run winform, the system copiesSource codeThe app_code directory of the CS file at the same directory is under the bin directory, and the MDF file under the bin directory is connected.
In this way, I will overwrite the bin \ app_code \ *. MDF file every time I run it. Naturally, I cannot modify it. It's really depressing!
Mount the MDF file directly to sqlserver. Modify the settings file to connect to the MDF file instead of the MDF file in sqlserver mode. The program is normal!
If debugging is not performed, directly copy the items under the bin directory during release. It is estimated that there will be no problem. Or we can consider placing the app_code directory under the bin directory instead of the Cs source.CodeFile at the same directory level. this is because I considered that there was no problem in Asp.net and followed winform. this is also natural. The connection group is very internal database = | datadirectory | \*. MDF represents the current path in webform, and it is indeed the bin directory in winform.
So be careful. Haha