When accessing the database in Asp.net 4.5. Use the data source control to access data. When using the linqdatasource data source control
"Source" [When configuring the data source] cannot display datacontext object. I have been searching for it for a long time on the Internet. I finally figured it out through my own exploration...
1,The first step is to determine the database instance type and authentication method you selected.
In Microsoft's database management system, the database instance types include SQL Server, sqlexpress, and localdb. Different instance types determine the web of your project. the value of data source in the database connection string in the config file. You can open the database file in the app_data folder of the project, or select
Click the change option in the figure and select the data source. Here, Microsoft SQL Server database file is selected, [another method is to double-click the database file in the app_data folder of your Asp.net project ],
After that, you will see Server Explorer, which appears in the database resource manager,
The system automatically adds the database connection string in Web. congfig,
2. Add a new item in the app_code folder and select the [LINQ to SQL class] template. If this component has not been installed, you can select the tool menu, enter the vs installer, and add the component,
,
In the Open Server Explorer [database resource manager] window, select the connection to expand tables (table), drag and drop all data tables to the new XXXXX. the operation is completed in the object relation designer of the dbml file ., Make sure that the code of the design. CS file expanded in the xxxxdbml file is generated successfully. Otherwise, we recommend that you try again ,,,,
3. Create a web form File
,. Aspx file code,
Select the design option in the lower left corner of the. aspx file. You can see the Smart tag in the upper right corner of the linqdata control and click Configure data source.
You can see the results... if the show only datacontext objects check box is displayed as blank, it indicates that the database connection configuration is incorrect or the. dbml file is faulty. Please return and try again ,,,
The hidden code file is:
Use LINQ to SQL to query data. The myexercisedbdatacontext object dB is the class instance in the xxxdesigher. CS file automatically generated by our previous tool, which is inherited from datacontext.
Finally, view the effect in the browser ,,,
In addition, if an error is generated when you create a file of the same SQL class as LINQ, you can try to change the file path, not in the app_code folder ..
About linqdatasource configuration data source [IN vs017 environment]