My ASP.NET note. (Oh, try it)

zhaozj2021-02-11  240

ASP.NET notes

Time: January 14, 2003

Topic: DataGrid Control Reproduction

First, the problem is proposed

1. Problems with DataGrid Controls and Dataset in the Microsoft Tutorial

DataGrid is used in the QuickStart tutorial of MICORSOFT to display data. Its example can be very convenient to use the VS wizard to implement, just write a small amount of code. However, there is the following problems in efficiency:

• DataGrid controls must be databind each time you are displayed, and each DATABIND has to re-read all the required data in the database to DataSet. This is almost unacceptable in actual use.

• There are no tools such as VS in the example, and the connection string in the ASPX file cannot be shared. In fact, we often have to debug files on your own machine. Then upload the file to the server, at this time, the xxxConnection string of the database is often modified, and such a string is distributed in different parts of different files, and the modification makes people hample (afraid to have omissions). In fact, most of them are the same database, that is, the same connection.

2, Dataset's embarrassment

What is the purpose of Microsoft to DataSet? I am a bit confused now:

As an initiator, I think dataset is really a good thing. At that time, I only spent two lines of code plus VS wizard, using DataGrid showed all the contents in all tables; all this makes it easy to use DataSet.

However, I am very happy. DataSet In the default, all the relevant content is fully loaded into memory, not only the content you need to display. The MS document says that DataSet is suitable for data that needs to be repeatedly modified, but I am still confused: because DataSet is not public. In other words, each user has its DataSet, which is generally not one, because the Dataset is not saved in ViewState, so it is generally cache or session before POSTBACK, so that the server's memory has two DataSet. Assume that each DataSet accounts for 1M (small table), then 100 users will make your server can't eat.

However, DataSet is indeed more convenient! Performance and convenience, fish with bear's paw.

Second, solve ideas

1. Custom read DataSet data related to DataGrid. Since DataGrid cannot be directly handled with DataSet, the related content such as page pages must be rewritten.

2, use web.config to connect string sharing. The benefits of the DataAdapter wizard are convenient, but it cannot directly use the contents of the web.config, so they have to write the corresponding code. Unfortunately! However, the code of the wizard is too much too long, and the handwriting is simple. L

3, use DataSet or DataReader?

It is hesitant for a long time. Many related examples are DataReader, but I am lazy, everything is simple. So, I still chose DataSet, just only the content that is necessary (display). After the display is release, it should not be stored.

Third, the goal:

Fourth, process

1,

Use Web.config

(1)

Add: in Web.config:

(2)

Use in the VB code:

CNN = New SqlConnection (ConfigurationSettings.AppSettings (). Item ("Connectionstring"))

'The above statement is equivalent to CNN = New SqlConnection ("Data Source = TMS; Initial Catalog = MyGuest; Integrated Security = SSPI; PERSIST Security Info = False; Workstation ID = TMS; Packet Size = 4096"

Da = New SqldataAdapter ("Select Employeeid, Lastname, Firstname, City from Employees", CNN)

Da.fill (DS, "Employees")

(3)

Description:

· Explanation about Security = SSPI

Integrated security - or -

Trusted_Connection

'False'

This connection is a secure connection. The identifiable value has "True", "False" and "SSPI", the latter is equivalent to "True".

· Explanation about PERSIST Security Info = False:

If the "continuous security information" value is set to false (default), the returned connection string is the same as the user-set constribionString but removes security information. The SQL Server .NET data provider does not continue or returns the password in the connection string unless "continuous security information" is set to TRUE, otherwise.

****** The above explanation is not very clear

· Explanation about Workstation ID

User ID

SQL Server login account.

Workstation ID

Local computer name

The name of the workstation connected to SQL Server.

· Description of ConfigurationSettings:

Provides access to configuration settings in the specified configuration section that cannot be inherited.

Public property

Appsettings

Get the configuration settings in the Element Configuration section.

Public approach

GetConfig

Returns the configuration settings for the user-defined configuration section.

转载请注明原文地址:https://www.9cbs.com/read-4265.html

New Post(0)