. Some bugs in the net Official edition and their solutions

Source: Internet
Author: User
Tags foreach config ole
Solve. NET official version of some bugs and their solutions (original)
Author: Flying Knife
(1) The question of the session

Problem:

In my windows.net 3604 +. Net Framework formal programming environment,. NET under the session is always a problem, such as I have a program under the set up a conference dictionary, which will be read under the B program, the situation is that I read this session in B program, the first time to read normally, But once the page is submitted (which is often the case in asp.net programming), the session disappears and the error report "Object is null", using trace to find that the session no longer exists.

This issue excludes the possibility that the browser does not support cookies because it is normal for me to read cookies.

Workaround:

Using the cookieless state of the session, the specific action is to change the Web.config or Machine.config file so that the value of the session is carried out in the URL.
Using Cookie,cookie can be used normally, as long as the browser does not turn off this feature.
(2) The problem of FindControl method

Problem:

We all know that there is a FindControl method for all control collections, and the most commonly used place is the DataGrid's action on controls in item. It's a good way to get the controls we want quickly, but he's also the most unstable way I've ever met.

Use this method in the item, generally does not have what problem, but in the DataGrid, DataList of various events of this method often cannot find the control!! The DataGrid is a little bit, DataList events in the situation is appalling, 100% can not find the control!! This control is alive and can be found in the Controls collection. This question I have discovered under the BETA2, originally thought that Microsoft will correct in the official version, does not know that is no one to propose? Still not found, the official version is still the case.

At first I thought FindControl this method was not written well, and I rewrote it myself, but when I was happy to use my own method of writing, I found that the return value was still NULL!!! Now there's only one explanation, and that's. NET environment, support for the control type is still unstable.

Workaround:

That is, by writing the method to return the value of the method, then only in the most original method, in this function, directly enumerate the control in the Controls collection until the control is found.

private void Showquestion_itemdatabound (object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Null values often occur when the return value is the control type

foreach (Control cl. e.item.controls)
{
if (CL. Clientid.indexof ("OptionalTd1")!=-1 | | Cl. Clientid.indexof ("OptionalTd2")!=-1)
{
foreach (Control clx in CL. Controls)
{
if (CLX. Clientid.indexof ("OPLBL1")!=-1 | | Clx. Clientid.indexof ("Oplbl2")!=-1)
{
if ((Label) CLX). Text = "")
{
((HtmlTableCell) CL). InnerHtml = "";
}
}
}
}
}

Is the programmer will be on the above method Chi's nose, but there is no way, Microsoft forced me to embark on this road, otherwise there is no way to find the dongdong I want.

(3) Problems with OLE DB

Problem:

We all know that. NET platform there are two ways to access the database, one is SqlClient, the other is oledb,sqlclient is designed for SQL Server, in order to ensure the compatibility of the program, we still have to use OLE DB.

Using OLE DB is a painful thing to have, with superhuman willpower and patience, to write a program using OLE DB and to have a nightmare is no different, people really don't know where the myriad of errors are. First look at the following program.

String strinsertread = "Insert into UnRead (Judge1_result,judge2_result)";
Strinsertread + = "Values (@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 ();

What mistakes do you think will be reported in implementing such a procedure? (Note that myconn is a OleDbConnection instance, already open)

The error reported is "The input data type does not match the database field type!!" ”?

I've been thinking about it for a long time? Strjudge1_result and Strjudge2_result are string, and the corresponding field in the database is "TEXT", how does it match? It's impossible. No way, I change the database type of the field try to get the data into the database, and then directly from the database to see what data is entered?

A look do not know, a look on my anger, into the database is not Strjudge1_result and Strjudge2_result expressed the results of the judgment, but set the other variable idcard and template, two irrelevant variables how would get together?? I use trace to view the Strjudge1_result data before warehousing is correct, which means that the problem occurred in the warehousing, here is the Parameters property to do good!

I changed all of OLE DB in this program to SQL, the program all normal! I can only say that OLE DB database operation is garbage (perhaps a bit overdone), if you operate OLE DB a bunch of problems, you have to trust yourself, some things are not your fault, but Microsoft does not want you to use other databases.

Workaround:

If you are operating SQL Server, then I recommend that you use SqlClient directly, which eliminates a lot of hassle. If you do not want to use OLE DB to manipulate other databases, use the parameters attribute as little as possible to pass arguments, but write directly into the SQL statement:

String strinsertread = "Insert into UnRead (Judge1_result,judge2_result)";
Strinsertread + = "Values (' +strjudge1_result+" ', ' "+judge2_result+") ";




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.