public void open()
{

myconn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("VIP.mdb"));
myconn.Open();
}我想在类里写好连接数据库??可是这样不行,提示找不到类型或命名空间名称"Server" ,要怎么写呢?

解决方案 »

  1.   

    System.Web.HttpContext.Current.Server.MapPath();
      

  2.   

    建议楼主将数据库连接字符串写进配置文件web.config中.
    如:
    <configuration>
      <appSettings>
        <!--连接Sql Server数据库信息-->
        <add key="SQLConnString" value="Provider=Microsoft.Jet.Oledb.4.0;Data Source=数据库绝对路径" />
      </appSettings>
    </configuration>
      

  3.   

    mycommand=new OleDbCommand("update [card] set cardid='"+username.Text+"',jf=jf+convert(int,"+jf.Text+") where id="+sid+"",obj.myconn);标准表达式中数据类型不匹配。哪里错了。jf=jf+convert(int,"+jf.Text+")
      

  4.   

    string sql="update [card] set cardid='{0}',jf=jf+{1} where id={2}";
    string.Format(sql,username.Text,jf.Text,sid);
    mycommand=new OleDbCommand(sql,obj.myconn);
    改成这样试试
      

  5.   

    string sql="update [card] set jf=jf+{0} where cardid={1}";
    string.Format(sql,jf.Text,cardid.Text);
    OleDbCommand mycommand=new OleDbCommand(sql,obj.myconn);不正常 GUID。 在查询表达式 'jf+{0}' 中。 
      

  6.   

    public void open()
    {OleDbConnection myconn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+System.Web.HttpContext.Current.Server.MapPath("VIP.mdb"));
    myconn.Open();
    }