Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What problems should be paid attention to in creating ADO.NET parameters

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "create ADO.NET parameters should pay attention to what problems", the article explained the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "create ADO.NET parameters to pay attention to what problems" bar!

The pictures in the website can be saved to the file system, that is, a special directory for the storage of pictures, which is coupled with the image path information saved in the database. ADO.NET parameters believe that many websites are selected in this way. Due to the separation of storage and management information, this collocation has the advantage of having little impact on the performance of the database.

But it is precisely because the directory structure of this separate website can not be changed easily, in addition, the backup of image data needs to be synchronized between the database and the file directory. Another way to store and manage pictures in addition to the ADO.NET parameter is to store the pictures in the database. If the number of pictures on the site is not too many and the pictures are not too large, this method is quite suitable. In this article, we look at how to use ADO.NET Entity Framework to build a data access layer to store and retrieve pictures from a database.

Preliminary work: create data table with ADO.NET parameters + build data access layer

* * step to create a data table. A field is required to save the image in the table. The type is set to image, and the code is as follows:

CREATE TABLE [dbo]. [images] ([id] [int] IDENTITY (1) NOT NULL, [imagefile] [image] NOT NULL)

The second step is to build the data access layer. The insertion of this type of data is different from the general basic SQL type, but programmers working on the .net 3.5 platform do not need to think too much about the specific code to access the database. We can choose ADO.NET Entity Framework and Linq to SQL. Here we take the former as an example. The method is briefly introduced as follows:

New in the project, select ADO.NET Entity Data Model, according to the wizard to establish a connection to the database, according to the wizard to select the table just established in the database images,ADO.NET parameters wizard after the end of the wizard will add an edmx type file in the project, the default interface will open the automatically generated entity class diagram, all the tables we select in the wizard will correspond to an entity class with the same default name as the data table The entity class corresponding to images here is also images, but it will cause ambiguity if it is used by default, and we need to modify it manually.

Click the images class in the properties dialog box to change the Name attribute to image,Entity Set Name or leave images unchanged to represent the image collection, and the corresponding class name in the entity class diagram becomes image after the ADO.NET parameter. This assumes that the database where the images are stored is named XXX, then the generated management class, which we use most frequently later, is called XXXEntities.

Save the picture to the ADO.NET parameter, first declare a variable of type image, call it img, image img = new image (); and then create a XXXEntities object, XXXEntities XXX = new XXXEntities (); add a FileUpload control to the asp.net web page, which provides a property PostedFile that provides an input and output stream for the server, just enough for us to read the selected image into the server's memory

Thank you for your reading, the above is the content of "what problems to pay attention to in creating ADO.NET parameters". After the study of this article, I believe you have a deeper understanding of what problems you should pay attention to in creating ADO.NET parameters, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report