0

我开始了 Windows 窗体的新项目。第一页是UserLogin。在表单加载事件中,我将登录表从数据库放入内存。我正在使用一个存储所有读写操作方法的类。

当我在 formload 事件中调用类时,错误出现“在当前上下文中不存在”

我可能缺少一些参考资料或头文件名..

请帮助提前谢谢

   using System;
   using System.Collections.Generic;
   using System.ComponentModel;
   using System.Data;
   using System.Drawing;
   using System.Linq;
   using System.Text;
   using System.Windows.Forms;
   using System.Configuration;
   using System.Web;

   namespace InvestmentAndReturns
  {
public partial class UserLogin : Form
{
    public UserLogin()
    {
        InitializeComponent();
        CenterToScreen();
    }

    public string UserID = null;
    private string userPass = null;
    public string UserGroup = null;
    DataTable UserLoginTable;
    int logintry = 1;
    public bool LoginStatus = false;

    private void Form1_Load(object sender, EventArgs e)
    {
        txtUserID.Select();

        string cmd = "Select * from UserLogin";
        UserLoginTable = DbRdRw.SqlDbRead(cmd, "UserLogin");
    }

DbRdRw:这是类 SqlDbRead:这是读取方法

4

1 回答 1

0

我已经通过直接将其粘贴到项目文件夹中来包含该类,然后打开解决方案,然后将其包含在项目中

看起来您已经复制粘贴的源文件,其中包含DbRdRw来自其他项目的定义 - 这主要意味着namespace文件中的声明将来自旧项目。

如果您将命名空间更改为当前项目,一切都会奏效InvestmentAndReturns

但是,你为什么要复制粘贴呢?您可以为您制作一个库 dllDbRdRw并引用该 dll。这样您就可以将源代码保存在一个地方。

于 2013-06-25T12:45:21.100 回答