3-tier WinForms C# Datagrid. Having trouble filling the grid with values from different queries.

  • Thread starter Thread starter Gabbelino
  • Start date Start date
G

Gabbelino

Guest
Hi!

I'm currently trying to fill my datagridview with values from different queries.

I've started to try and add the result from one query to a specific column. Problem is that since i haven't had much focus on datagridviews i'm somewhat lost i've tried looking up different ways to add values to rows, only that most post or guides want to use SqlClient with the classic "Sqlconnect con= new SqlConnect();"

and bind the data with a different approach than what i'm using.

I'm focusing on getting 1 query added to the datagridview to the correct column before i start making the rest, since i believe getting one to work may be a learning experience that can be applied to the other queries.

This how the presentation layer looks like right now:

//the code in presentation layer

BusinessManager bm = new BusinessManager();

int agentId = int.Parse(cbAgent.Text.Trim());
int year = int.Parse(Year.Text.Trim());
int month = int.Parse(Month.Text.Trim());
var dtYear = new DateTime(year, 1, 1);
var dtMonth = new DateTime(1, month, 1);

bm.ChildInsurance(agentId, dtYear, dtMonth);

In the datagridview I have a column named Child Insurrance which I want the result from the query to be added.

in business layer it looks like this:

public int ChildInsurrance(int agentId, DateTime year, DateTime month)
{
int sum = dm.ChildInsurranceSum(agentId, year, month);
return sum;
}



And this is the query in data access layer which i will modify, right now i'm just want the value sent and presented in the datagrid:

public int ChildInsurranceSum (int agentId, DateTime year, DateTime month)
{
DataModelContainer db = new DataModelContainer();
var sum = (from x in db.InsurranceSet
join y in db.PrivateApplicationSet on
x.Privateapplication.privateApplicationId equals y.privateApplicationId
where x.paydate == year & x.paydate == month && y.Agents.agentId == agentId
select x).Count();
return sum;


}

Any suggestions? Or do you need more info?

Regards

Gab


NOTE: the variables has been translated to easier to understand.




Student at the University of Borås, Sweden

Continue reading...
 
Back
Top