Jag försöker att få ihop en liten smidig class men det skiter sig.
Min class
public static decimal OleDbCount(string sql, OleDbConnection DBConn)
{
decimal sText = 0;
try
{
OleDbCommand OleDbCmd = new OleDbCommand();
OleDbCmd.CommandText = sql;
OleDbCmd.Connection = DBConn;
DBConn.Open();
sText = (int)OleDbCmd.ExecuteScalar();
return sText;
}
catch { }
finally { DBConn.Close(); }
return sText;
}
}
//detta fungerar jag skickar alltså in en sql här
public decimal CountSQL(string sql)
{//string strSQL = "select count(*) from Produkter ";
decimal sText = 0;
try
{
sText = (decimal)WebbUtill.OleDbCount(sql, DBConn);
return sText;
}
catch{ }
return sText;
}
//detta fungerar inte jag kommer till en sida som inte visar någonting
public decimal HowMuchWillItCost(string productName, int howMany)
{
try
{
if (howMany > 0)
{ string sql = "Select Enhetspris FROM Produkter WHERE
Produktnamn = '" + productName + "'";
decimal price = (decimal)WebbUtill.OleDbCount(sql, DBConn);
return price * howMany;
}
else
{
throw new Exception("\n" + " howMany cant bee negative.");
}
}
catch (Exception e)
{
throw new Exception("Error calculating cost: " + e.Message);
}
decimal varde = 0;
return varde;
}
Någon som kan se felet???