Click here to Skip to main content
15,884,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
+++
C#
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
+++
C#
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
+++
C#
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);
        }
}
Posted
Updated 25-Nov-12 22:31pm
v2
Comments
Herman<T>.Instance 26-Nov-12 6:58am    
in the first block of code you define
PersonBLL _localpers = null;

but in button1_click you do not use the _localpers but directly call the PersonBLL
private void button1_Click_1(object sender, EventArgs e)
{
try
{
_localdt = PersonBLL.GetAddressesFromPerson(textBoxBranchName.Text);

Shouldn't that be:
_localdt = _localpers.GetAddresFromPerson..... ?

Hi,

Update your code and see the result.
C#
_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.
C#
dataGridViewAddresses.Grid.DataSource = localdt.Tables["Addresses"];
 
Share this answer
 
v2
after
C#
dataGridViewAddresses.DataSource = _localdt.Tables["Addresses"];
dataGridViewAddresses.Refresh();
DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900