获取错误当前上下文中不存在名称“DB” [英] getting error the name 'DB' does not exist in the current context

查看:338
本文介绍了获取错误当前上下文中不存在名称“DB”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手。我正在Visual Studio 2008(在线巴士票务项目)中编写一个项目,但我不断收到此错误:当前上下文中不存在名称''DB''。我真的很困惑,不知道我的代码中有什么问题。我发布了代码belo。我将不胜感激任何帮助。

Hi, I am new to C#. I am writing a project in Visual Studio 2008(online bus ticketing project) but I keep getting this error: "the name ''DB'' does not exist in the current context". I am really confused and don''t know what could be wrong in my code. I have posted the code belo. I would be grateful for any help.

using System;
using System.Web;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class MasterPage2 : MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.litdate.Text = DateTime.Now.ToString("D");
        if (this.Page.User.Identity.Name.ToString() != "")
        {
            this.litbal.Text = DB.ExecuteScaler(string.Format("Select Agent_current_bal from AgentBasicInfo where Agent_ID=''{0}''", this.Page.User.Identity.Name.ToString().ToLower())).ToString();
        }
        else
        {
            this.up12.Visible = false;
        }
        this.submenu.Visible = this.Page.User.Identity.Name.ToString() == "admin";
        this.lblCreatedBy.Text = "Created By: Christopher Mutoborokho";
    }

}

推荐答案

你需要这样的东西和你一样有:


You will need something like this to go along with what you have:

string strSQL = string.Format("Select Agent_current_bal from AgentBasicInfo where Agent_ID=''{0}''", this.Page.User.Identity.Name.ToString().ToLower())).ToString();

 OleDbConnection conn = new OleDbConnection("Your connection string");
 OleDbCommand cmd = new OleDbCommand(strSQL, conn);
 conn.Open();
 OleDbDataReader dr1 = cmd.ExecuteScalar();


这篇关于获取错误当前上下文中不存在名称“DB”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆