Two o'clock in the morning, I made a new article release program .. Many problems

Source: Internet
Author: User

It uses a general database metadata class UnDbAccess, which mainly implements the following methods:

1. ExecuteNonQuery: Execute SQL statements such as INSERT, DELETE, and UPDATE and return the number of affected rows.

2. ExecuteReader: Execute the SELECT Operation and return a data reader object.

3. ExecuteScalar: Execute the SQL operation and return the single-value object, that is, the first data in the first row of the result set.

4. PopulateDataSet: Execute an SQL operation to populate the data obtained from the data source with the DataSet object through the data adapter object.

And return it.
------------------------------------------------
Of course, what others wrote

There are many problems. I put common operations in a newspublic class, such as accessing common information (site name, address, email:
Public class NewsPublic
{
Private string siteName, siteUrl, siteMail, siteLogo, siteAd, newsAd, affiche;


Public NewsPublic ()
{
UnDbAccess uda = new UnDbAccess ();
OleDbDataReader dr = (OleDbDataReader) uda. ExecuteReader (SELECT * FROM SiteConfig WHERE id = 1 );
If (dr. Read ())
{
SiteName = dr ["db_SiteName"]. ToString ();
SiteUrl = dr ["db_SiteUrl"]. ToString ();
SiteMail = dr ["db_SiteMail"]. ToString ();
SiteLogo = dr ["db_SiteLogo"]. ToString ();
SiteAd = dr ["db_SiteAd"]. ToString ();
NewsAd = dr ["db_NewsAd"]. ToString ();
Affiche = dr ["db_Affiche"]. ToString ();
}

}

---------------------------------
Then on the homepage default. aspx is called:

Public class _ default1: System. Web. UI. Page
{
Private NewsPublic np;
Protected System. Web. UI. HtmlControls. HtmlForm Form1;
Protected System. Web. UI. WebControls. DataGrid DataGrid_ShowAll;
Protected System. Web. UI. WebControls. Literal L_Affiche;
Protected System. Web. UI. WebControls. DataGrid DG_HotNews;
Protected System. Web. UI. WebControls. Literal SiteTitle;

 
Private void Page_Load (object sender, System. EventArgs e)
{
If (! Page. IsPostBack)
{
Np = new NewsPublic ();
SiteTitle. Text = np. SiteName;
Rochelle affiche.text = np. Affiche;
ShowNewsAll ();
ShowHotNews ();
}
}

The display is normal. After refreshing several times, the problem arises:
System. NullReferenceException: object reference is not set to the instance of the object.
In the newspublic class.
OleDbDataReader dr = (OleDbDataReader) uda. ExecuteReader (SELECT * FROM SiteConfig WHERE id = 1 );
If (dr. Read ())
In this case, uda. ExecuteReader returns null.
What's going on with this? It will be easy to use after refresh. After several refresh attempts, the System. NullReferenceException will be prompted.
I have a headache ......... Someone else gave me some advice.

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.