|
i have the decimal point saved in my database as decimal_point field and i am saving it in a hashtable key to be used in my whole application.. now my question, how can I use that figure to format all the numeric numbers to have the same decimal points as my decimal_point value?
do I have to say:
if decimal_point = 0 then format it as zero
else if decimal_point = 0 then format it as one
else if decimal_point = 0 then format it as two
else if decimal_point = 0 then format it as three
or there is a better way to do it?
|
|
|
|
|
Do you mean something like this:
decimal decVal = 984.125m;
int nDecimalPoint = 2;
string szFormattedValue = decVal.ToString("F" + nDecimalPoint.ToString());
Greetings
Covean
|
|
|
|
|
what about the textbox mask?
|
|
|
|
|
The problem is, intermittently i get the error:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005.
It throw up when I use:
Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
and it happens randomly.
What could be the reason?
Dose anyone have any experience with this,thanks in advance for ur assistance.
modified on Wednesday, June 23, 2010 5:15 AM
|
|
|
|
|
Hi all
how to transfer values from one datatable to another datatable. For example there are 2 datatables Table A and Table B. If then column name in Table A is the same as Table B then all the values of that column will go into Table B of the same column name.
Hope you understand me.
Thank you
zheng
|
|
|
|
|
For Each dr As DataRow In sourceTable.Rows
destinationTable.ImportRow(dr)
Next
sourceTable is Table A
destinationTable is Table B
|
|
|
|
|
If you want to add a new column from table A to table B
you should foreach the data row of the table a
DataTable b, a;
foreach (DataRow dr in a.Rows)
{
string id = dr["id"].ToString(); DataRow[] bDr = b.Select(string.Format("id = '{0}'", id));
bDr[0]["value"] = dr["value"];
}
|
|
|
|
|
I am coding this utility to test raising of an exception, however, I have noted that Visual Studio 2010 IDE does not allow me to call the ArithmeticUtilityException.Divide() method. Why?
I have also (desperately) tried to declare the class as static and the Divide() method as static, however, no joy either.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CustomException
{
class Program
{
static void Main(string[] args)
{
ArithmeticUtilityException utility = new ArithmeticUtilityException();
}
}
public class ArithmeticUtilityException : ApplicationException
{
public ArithmeticUtilityException() : base() {}
public ArithmeticUtilityException(string message) : base(message) {}
public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
}
public static class ArithmethicUtility
{
public decimal Divide(decimal number, decimal divisor)
{
try
{ return number / divisor; }
catch (Exception err)
{
ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
throw errNew;
}
}
}
}
NOTES
1. Related link Static Classes and Static Class Members (C# Programming Guide)
2. Personal note. ..\Training\CustomException.
Jon
|
|
|
|
|
jon_80 wrote: does not allow me to call the ArithmeticUtilityException.Divide() method. Why?
Because you don't have one?
public class ArithmeticUtilityException : ApplicationException
{
public ArithmeticUtilityException() : base() {}
public ArithmeticUtilityException(string message) : base(message) {}
public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
}
public static class ArithmethicUtility
{
public decimal Divide(decimal number, decimal divisor)
{
...
}
}
Divide is a member of ArithmethicUtility, not ArithmeticUtilityException
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CustomException;
namespace CustomException
{
class Program
{
static void Main(string[] args)
{
ArithmethicUtility utility = new ArithmethicUtility();
Decimal myNumber = utility.Divide(5, 0);
}
}
public class ArithmeticUtilityException : ApplicationException
{
public ArithmeticUtilityException() : base() {}
public ArithmeticUtilityException(string message) : base(message) {}
public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
}
public class ArithmethicUtility
{
public decimal Divide(decimal number, decimal divisor)
{
try
{ return number / divisor; }
catch (Exception err)
{
ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
throw errNew;
}
}
}
}
Jon
|
|
|
|
|
You're welcome.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
There is a com dll written by C++ ATL. There is no embedded type library resource in it, although I have its type library(.tlb file) seperately.
I can't add it to my C# project references. So, how should i do to use it?
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:18am.
|
|
|
|
|
Thanks for your reply. As we know, an atl com dll only export five functions:
DllCanUnloadNow,DllGetClassObject,DllRegisterServer,DllUnregisterServer.
So, im afraid that couldn't help to reach my aim, right?
|
|
|
|
|
Because it exports the function DllRegisterServer I would assume, that this COM dll isn't
registered. Just use the regsrv32.exe to register it.
Example:
regsvr32.exe [Path]example.dll
After you registered it, it should be visible in the COM tab of the "add reference" wizard.
Greetings
Covean
|
|
|
|
|
Oh, of course the com dll has been registered successfully. When add its reference by vs(it can be listed in the com tab list), vs will give me an error messagebox says "A reference to '*** Type Library' couldn't be added. This is not a COM component". But, if the dll has embedded type library in it, it will be ok.
|
|
|
|
|
Sorry but I never ran in this problem, so I never had to find a solution for this.
Greetings
Covean
|
|
|
|
|
Oh, thanks all the same. I will be glad to tell you the solution if i got it.
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:17am.
|
|
|
|
|
My be. But my main problem is create the component class.
You know, in C#, i just reference the com dll. If i have to use the raw com dll file as common unmanaged dll, im not sure how to create the object and how to translate parameters.
So, I hope to add referenct it via its type library(.tlb file).
|
|
|
|
|
I am trying to put this into actual class and i am having difficutlties in it. I am not sure how to show relationships. I have put down some classes that it may need.
Build a class called Employee reporting relationships. The class will be used as a part of some application. Its main purpose is to keep and maintain data related to the reporting relationships between employees within an organization.
Employee can have zero or more managers. Manager is an employee who has one or more other employees reporting to him.
Class EmployeeReportingRelationships
{
}
Class Employee
{
}
Class Manager:Employee
{
}
modified on Wednesday, June 23, 2010 1:47 AM
|
|
|
|
|
I'm afraid noone will do your homework for you.
Try thinking further, and come back with a more precise question.
|
|
|
|
|
Well, I am not asking to write exact code for me or atleast if you could engligten me with some ideas wouldn't be bad. I find hard to comphrend and put into OOP. I know how to write classes and properties but i am not so sure what to do in it.
|
|
|
|
|
So you need to break down the requirements into logical parts.
Employee can have zero or more managers.
So, your Employee class will need a property that has a variable size that is of type Manager . Perhaps a List<Manager>
Manager is an employee...
So the Manager class should derive from Employee as you have already done.
...who has one or more other employees reporting to him.
So the Manager class needs an additional property that has a variable size that is of type Employee . Possibly, the extra Manager class isn't needed as checking this property is > 0 will indicate that they are manager anyway.
This is what programming is all about, turning real world situations into code and in the case of OOP creating objects to represent them and adding properties to give the details/descriptions of thos objects and methods/events for the things they actually do. Not really that hard to grasp.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks Dave, your comments were really helpful. I've given you my vote of 5.
However there is still a little confusion about the relationship, how could i get a list of managers for a given employee. For example, let's say I have an employee named "Frank" and he has two managers (Sean and manager2).
|
|
|
|