数据集未填充数据网格 [英] DataSet does not fill datagrid

查看:85
本文介绍了数据集未填充数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题.在GUI中,我的数据网格未填充.
但是,当我从consoleapp调用bll方法时,会得到结果.
谁知道有什么毛病?

GUI
+++

I have this issue. In the GUI my datagrid is not filled.
However when I call the bll method from my consoleapp, I get the result.
Someone who knows what can be wrong?

GUI
+++

PersonBLL _localpers = null;
        
private void button1_Click_1(object sender, EventArgs e)
{
	try
        {
                _localdt = new DataTable("GeneralInfo");
                _localdt = PersonBLL.GetAddressesFromPerson(textBoxBranchName.Text);
                dataGridViewAddresses.DataSource = _localdt.Tables["Addresses"];
                dataGridViewAddresses.Refresh();
        }
        catch (Exception ex)
        {
                MessageBox.Show(ex.Message, "Person",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
}



BLL
+++



BLL
+++

public static DataTable GetAddressesFromPerson(string name)
{
	try
        {
                return PersonDAL.GetAddressesFromPerson(name);
        }
        catch (BranchDALException ex)
        {
                throw new PersonBLLException(ex.Message);
        }
        catch (Exception ex)
        {
                throw new PersonBLLException(ex.Message);
        }
}



DAL
+++



DAL
+++

public static DataTable GetAddressesFromPerson(string name)
{
	try
        {
                int persid = PersonDAL.GetPersonID(Name);

                string sql = "SELECT * FROM ADDRESS WHERE PersonId=@persid";

                CommandParameterList localparams = new CommandParameterList();

                localparams.Add(new CommandParameter("@persid", persid, DbParameterTypes.Int32, ParameterDirection.Input));

                localDAC.LocalParameters = localparams;

                return localDAC.ExecuteDT(sql, AssignmentTypes.SqlStatement, "Addresses");
       	}
        catch (SQLDacException ex)
        {
        	throw new PersonDALException(ex.Message);
        }
        catch (Exception ex)
        {
                throw new PersonDALException(ex.Message);
        }
}

推荐答案



更新代码并查看结果.
Hi,

Update your code and see the result.
_localdt = new DataTable("GeneralInfo");
_localdt = PersonBLL.GetAddressesFromPerson(textBoxBranchName.Text);
dataGridViewAddresses.DataSource = _localdt.Tables["Addresses"]; //Check it you are getting data into this line. 


如果它不起作用,则使用下面的行来绑定数据.


And if it is not working then use below line to bind data.

dataGridViewAddresses.Grid.DataSource = localdt.Tables["Addresses"];


之后
dataGridViewAddresses.DataSource = _localdt.Tables["Addresses"];
dataGridViewAddresses.Refresh();
DataBind();


这篇关于数据集未填充数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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