无法转换数据集

时间:2013-03-05 03:23:17

标签: c# sql ado.net

我收到错误在调试程序时,说无法将类型为“System.Data.DataSet”的对象强制转换为类型MyDatabase.DataSet'

我需要做些什么来修复它

private void btnLogin_Click(object sender, System.EventArgs e)
   {
    string strUser;
    string strPass;
    string sMsg = "";

    strUser = txtUserID.Text ;
    strPass = txtPassword.Text ;

    DataSet o_Find = new DataSet ();
    Users oUsers = new Users();

    try
    {
        o_Find = (DataSet)oUsers.FindData(strUser,strPass);
        sMsg = "Welcome " + o_Find.Tables ["Login"].Rows[0]["UserName"].ToString ();

        switch (strUser)
        {
            case "Admissions":
                frmAdmissions admitForm = new frmAdmissions ();
                admitForm.Visible = true;
                admitForm.Activate();
                break;
            case "Admin":
            case "Nurse":
            case "Doctor":
                frmMenu menuForm = new frmMenu ();
                menuForm.oCurrent.UserName = strUser;
                menuForm.Visible = true;
                menuForm.Activate();
                menuForm.SelectUser();
                break;
        }

    }

1 个答案:

答案 0 :(得分:0)

我认为问题出在这一行:

o_Find = (DataSet)oUsers.FindData(strUser,strPass);

您似乎已在代码中的某处覆盖了DataSet的含义。 (例如,什么是类型MyDatabase.DataSet?)

这应解决问题:

o_Find = (System.Data.DataSet)oUsers.FindData(strUser,strPass);