我的数据表在3层中无法正常工作 [英] My datatable doesn't work properly in 3-tier

查看:83
本文介绍了我的数据表在3层中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我采用一种形式来显示带有insert,update,delete的所有数据,但我在此代码中发现错误,我的BindGrid()是

但我在此"return dTable;"中发现了错误;

Hi. I take one form for displaying all data with insert,update,delete but i found error in this code my BindGrid() is

but i found error in this "return dTable;"

private DataTable BindGrid()
      {
        PersonBAL3 p = new PersonBAL3();
        try
        {
          DataTable dTable = p.Load();
          GridView1.DataSource = dTable;
          GridView1.DataBind();
        }
        catch (Exception ee)
        {
          lblMessage.Text = ee.Message.ToString();
        }
        finally
        {
          p = null;
        }
        return dTable;
     }


推荐答案

将"dTable"的声明移至try block之外:
Move the declaration of "dTable" outside the try block:
private DataTable BindGrid()
      {
        PersonBAL3 p = new PersonBAL3();
        DataTable dTable = null;
        try
        {
          dTable = p.Load();
          GridView1.DataSource = dTable;
          GridView1.DataBind();
        }
        catch (Exception ee)
        {
          lblMessage.Text = ee.Message.ToString();
        }
        finally
        {
          p = null;
        }
        return dTable;
     }


这篇关于我的数据表在3层中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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