I have a MS access database with a table called tarriff_table. In this table I have two columns upperLimit & perUnitCost. I have a form to insert this values. Now I want to use these values to calculate in code. I have the structure of the code but I am unable to connect database values to the variables I used.
Here is the code.
double demandCharge, VAT,upperLimit1, upperLimit2;
double perUnitCost1, perUnitCost2;
private void button1_Click(object sender, EventArgs e)
{
double con_unit = 0, bill = 0, mcon_unit = 0, totalbill = 0;
con_unit = double.Parse(textBox1.Text);
mcon_unit = double.Parse(textBox2.Text);
if (con_unit < upperLimit1)
{
bill = con_unit * perUnitCost1;
}
else if (con_unit < upperLimit2)
{
bill = (upperLimit1 * perUnitCost1) + ((con_unit - upperLimit1) * perUnitCost2);
}
else bill = (upperLimit1 * perUnitCost1) + ((upperLimit2 - upperLimit1) * perUnitCost2);
totalbill = Math.Ceiling((((((bill + demandCharge) * VAT)
+ (bill + demandCharge)) / (con_unit)) * (mcon_unit)));
textBox3.Text = Convert.ToString(totalbill);
}
This is a part of the code. But I assume it can generate the problem I am facing. Here I want to connect upperLimit columns to upperLimit variable and perUnitCost column to perUnitCost variable. How can I do it?
I want these variables(upperLimit1, upperLimit2, perUnitCost1, PerUnitCost2) value to be pulled from a database.
Important Note: In the code section perUnitCost2 means the value of the second row of the perUnitCost column in the database.
Note: There is a work around possible by calculating all the values before inserting them into the database. by doing this compile time can be reduced to half. As the compiler doesn't have to insert values and again retrieve them perform calculation.
2nd Note: I have figured out that I need a connection string to connect to a database. I will like the moderators to close the topic.