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.