Hi all,
First introduce myself. :-) My name is Pieter and relatively new here.
I'm writing an N Tier app.
GUI -> BLL -> DAL -> DAC -> DB
I've got a datatable created and when I test it in my consoleapplication TestApp, I can access the result of my method like it should be. :-)
However when I try to access it with a datagridview it does not work?
A little example:
Class person
Class Address
I want to see all the addresses of 1 certain person.
In Dal I have a method called -> public static Datatable GetAllAddressesFromPerson(int PersonID)
In BLL I have a method called -> public static Datatable GetAllAddressesFromPerson(int PersonID) which just calls the DAL
IN GUI on the form load I should get some code that populates the datagrid
Issue:
Can not call the method.
DatagridviewAddresses = Datasource...
Datagridview refresh
Kind regards,
Pieter
Loading
Pieter TwentyeightPosted Nov 26, 2012, 3:43 AM
I guess there is a problem in the try section of the gui because the DAL and BLL were tested in my console app and worked fine:
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);
}
}
Shankar MPosted Nov 26, 2012, 3:13 AM
To assign the populated datatable details to the DataGrid we use the DataSource property,
DatagridviewAddresses.DataSource = PopulatedData;
Thanks,
Shankar