Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
+++
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
+++
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 25-Nov-12 23:22pm
Edited 25-Nov-12 23:31pm
v2
Comments
digimanus at 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..... ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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"];
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

after
 
dataGridViewAddresses.DataSource = _localdt.Tables["Addresses"];
dataGridViewAddresses.Refresh();
DataBind();
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 410
1 Sergey Alexandrovich Kryukov 350
2 ProgramFOX 275
3 Maciej Los 275
4 CHill60 260
0 OriginalGriff 360
1 ProgramFOX 265
2 Maciej Los 235
3 CHill60 200
4 RyanDev 170


Advertise | Privacy | Mobile
Web01 | 2.8.150331.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100