找不到表0

本文关键字:找不到 | 更新日期: 2023-09-27 17:59:11

我收到错误

找不到表0。

对此,我尝试了各种解决方案,但都解决不了。请帮忙。我的代码如下。

public void BG()
{
    DataTable dtDetails = null;
    string acadamicyear = ddlacadamic.SelectedValue;
    string Class = ddlclass.SelectedValue;
    string batch = ddlbatch.SelectedValue;
    string Status = ddlstatus.SelectedValue;
    dtDetails = objdal.GetEnqToGrid(acadamicyear, Class, batch, Session["branch"].ToString(), Status);
    if (dtDetails.Rows.Count > 0 && dtDetails != null)
    {
        gridadmission.DataSource = dtDetails;
        gridadmission.DataBind();
        lblmessage.Visible = false;
    }
    else
    {
        lblmessage.Text = "No records";
        lblmessage.ForeColor = Color.Red;
        lblmessage.Visible = true;
        gridadmission.DataSource = "";
        gridadmission.DataBind();
        return;
    }
}

找不到表0

您正在从GetEnqToGrid方法返回DataTable。在这种方法中,您正在填充DataSet,并在位置0返回可能尚未填充的DataTable。所以您需要检查DataSet是否包含表,然后返回它

if(ds.Tables.Count > 0)
 //return table;