换成先用字符串提取Application的值后错误变成:
编译器错误信息: CS0120: 非静态的字段、方法或属性“System.Web.UI.Page.Application”要求对象引用源错误: 行 12:   public DataRow myrow;
行 13:   public String newsid;
行 14:   public String mmm=(string)Application["strconn"];//这出错
行 15:   public void Page_Load(Object sender,EventArgs e){
行 16:      newsid=Request.QueryString["id"];
 
哪位大哥帮帮忙啊,在线等啊.....

解决方案 »

  1.   

    global.asax文件:
    <%@ Application language="C#" %><script runat="server">    public void Application_Start(Object sender, EventArgs e) {
            Application["strconn"]="server=localhost;database=putnews;uid=sa;password=19780225";
        }
    .........后台CS文件,它是一个ASPX页的后台:
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data;
    using System.Data.SqlClient;public class MyCodeBehind:Page
    {
      public DataRow myrow;
      public String newsid;
      public String mmm=(string)Application["strconn"];
      public void Page_Load(Object sender,EventArgs e){
         newsid=Request.QueryString["id"];
     SqlConnection conn=new SqlConnection(mmm);
     SqlCommand cmd=new SqlCommand("select * from aa where id="+newsid,conn);
     SqlDataAdapter myadapter=new SqlDataAdapter();
     myadapter.SelectCommand=cmd;
     DataSet mydataset=new DataSet();
     myadapter.Fill(mydataset,"news");
     myrow=mydataset.Tables["news"].Rows[0];
     myrow.BeginEdit();
     myrow["click"]=(int)myrow["click"]+1;
     myrow.EndEdit();
     myrow.AcceptChanges();  
     myadapter.Update(mydataset);
     
      }
      public string FormatString(string str) 
     { 
        str=str.Replace(" ","&nbsp;&nbsp;"); 
    str=str.Replace("<","&lt;"); 
    str=str.Replace(">","&gt;"); 
    str=str.Replace('\n'.ToString(),"<br>"); 
    return str; 
     } 
    }