Some BUGs in .NET official version and their solutions

zhaozj2021-02-12  149

(1) SESSION problem question:

In my Windows.net 3604 .NET Framework official version of the programming environment, session under .NET always has problems, such as I set up a session dictionary under the A program, this session will read under the B program. Now, when I read this session at the B program, I can read it normally, but once the page is submitted (this is common in ASP.NET programming), Session will immediately disappear, error Report "Object Is Null", use trace to find that this session does not exist.

This issue excludes the browser does not support cookie, because I read cookies is normal.

Solution:

1. Use the SESSION's cookieless status, the specific operation is changed to the web.config or machine.config file, so the pass value of the session is in the URL.

2. Use cookies, cookies can be used normally as long as the browser does not close this function.

(2) Problems with FindControl methods:

Everyone knows that all controls have a FindControl method, and the most common place is the operation of DataGrid to Item. This is a very good way to let us quickly find the controls we want, but he is the most unstable method I have encountered.

Using this method in Item, there is generally no problem, but in DataGrid, this method is often not found in the various events! ! DataGrid is better, the situation in the event of DataList is terrible, 100% can't find the control! ! This control is active, and this control can be found in the use of the Controls collection. I have discovered in beta2, I thought Microsoft will be corrected in the official version, I don't know if there is anyone to ask? Still not found, the official version is still like this.

I started to think that the method of FindControl didn't write. I used to renounce this method, but when I was pleased to use my way to write, I found that the value of the back is still null !!! Now there is only one Explain, that is, support for Control types in the .NET environment is still unstable.

Solution:

It's just that the method of writing the method is not used, then only the most original method is used, in this function, directly list the controls in the Controls collection until this control is found.

Privatevoid showquestion_itemdatabase (object sender, system.Web.ui.webcontrols.datalistitemeventageventArgs e) {// When the return value is a Control type, null value

Foreach (Control Cl In E.Item.controls) {if (CL.Clientid.indexof ("optionaltd1")! = -1 || cl.clientid.indexof ("optionaltd2")! = -1) {Foreach (Control CLX Incl.Controls) {if (CLX.ClientId.indexof ("oplbl1")! = -1 || CLX.ClientID.Indexof ("oplbl2")! = -1) {IF ((Label) CLX) .Text .Text == "" "(HTMLTableCell) Cl) .INNNERHTML =" ";}}}}} is the programmer to the above method, but there is no way, Microsoft force me to go to this road. Otherwise, there is no way to find the stuff I want.

3) OLEDB problem

problem:

Everyone knows that the .Net platform has two ways to have two ways. One is SQLClient, and the other is OLEDB, and SQLClient is designed for SQL Server. In order to ensure the compatibility of the program, we still have to use OLDB.

Using OLEDB is a painful thing, you must have a superman's willpower and patience, using OLEDB to write a program and do a nightmare, you don't know where the fellows are wrong. First look at the procedure below.

String strinsertread = "INSERT INTO unread"; strinsertread = "value" (@ Judge1_Result, @ Judge2_Result) ";

OLEDBCommand mycomm = new oledbcommand (StrinserRead, MyConn);

Mycomm.Parameters.Add ("@ Judge1_Result", OLEDBTYPE.LONGVARCHAR); MyComm.Parameters ["@ Judge1_Result"]. Value = strjudge1_result;

Mycomm.Parameters.Add ("@ Judge2_Result", OLEDBTYPE.LONGVARCHAR); MyComm.Parameters ["@ Judge2_Result"]. Value = strjudge2_result;

......

Mycomm.executenonquery ();

Execute such a program, what do you think will be reported? (Note MyConn is an OLEDBCONNECTION instance, which has been opened)

The wrong mistake is "Enter data type and database field type does not match !!"?

I thought for a long time? Strjudge1_Result and strjudge2_result are string, and how can the corresponding fields in the database are "text"? I am not impossible. There is no way, I change the database type of the field to try to enter the database, then view the recorded data directly from the database? I don't know, when I look at it, I will enter the database, and the database is not the result of the judgment indicated by strjudge1_result and strjudge2_result, but the other variable IDCard and Template, how the two unconcerable variables will be Go together? ? I use Trace to see if the data of Strjudge1_Result is correct, this means that it is a problem that occurs when the library is, this is a good thing to do!

I changed all the OLEDB in this program to SQL, and the programs are all normal! I can only say that OLEDB's database operation is garbage (maybe some fire). If you operate OLDB, you have to trust yourself, some things are not your fault, but Microsoft doesn't want you to use other databases.

Solution:

If you are working SQL Server, then I suggest you use SQLClient directly, so you have a lot of trouble. If you do not use OLEDB to operate other databases, try to transfer parameters using the parameters attribute, but write directly into the SQL statement:

String strinsertread = "INSERT INTO Unread"; strinsertread = "" Strjudge1_Result ", '" Judge2_Result "";

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

New Post(0)