|
Hi,
I just have a couple of questions:
If I have the following, what is the value of decEuro if the textbox txtEuro is empty? decimal decEuro = Convert.ToDecimal(txtEuro.Text.Trim());
Is decimal the best data type used for a currency value?
/********************************************************/
Check the following function:
public static Object CheckDecimalForDB(decimal decCheckDecimal)
{
if(decCheckDecimal != 0)
return decCheckDecimal;
else
return DBNull.Value;
}
The datatype/type returned when decCheckDecimal contains a value, is decimal, or Object?
/********************************************************/
I need to format data in a data grid, firstly time based on Culture info (South Africa), and secondly, decimal values to contain only 2 decimal places after the comma.
This is how I populate my datagrid with the 2 values:
<asp:Label id="lblDateRequested" Text='<%# DataBinder.Eval(Container.DataItem, "DateRequested", "{0 }") %>' runat="server" />
<asp:Label id="lblAgencyID" Text='<%# DataBinder.Eval(Container.DataItem, "Euro") %>' runat="server" />
"DateRequested" has a datetime datatype in SQL Server, and "Euro" is of type money.
/********************************************************/
I need to post data from one form to another form. I used Server.Transfer but then the new page doesn't display in the url "bar". Basically I just want the data to go from page A to page B. Usually in classic ASP I used Request.Form("txtFName") to get the value of the textbox in page A. I'm not sure if the Response.Redirect method does this, don't think so.
This is all for now, I hope to here from the experts soon.
Regards.
ma se
|
|
|
|
|
Surely if you are unsure of stuff like this, the best thing to do is create a simple console application and try it out?
decimal decEuro = Convert.ToDecimal(txtEuro.Text.Trim());
If the textbox is empty, you'll be trying to convert an empty string to a decimal, and an exception will be thrown so it'll never get as far as assigning decEuro.
public static Object CheckDecimalForDB(decimal decCheckDecimal)
{
if(decCheckDecimal != 0)
return decCheckDecimal;
else
return DBNull.Value;
}
The return type is Object which is the base type for everything. This object will either be a boxed value type of System.Decimal or reference type System.DBNull. You can use the .GetType() method to determine which.
Rob Philpott.
|
|
|
|
|
Thanks.
If the return type is Object, and I do return the decimal value, as for example 10.5, would I still need to convert the value to a decimal where it is being called, or will it assume that it is of type decimal?
Lets say the called is used like this:
paramPound.Value = Globals.CheckDecimalForDB(objProperty.Pound);
Does .value contain a decimal, or must I still use Convert.ToDecimal();??
Do you have any comments on formatting dates and decimal numbers in the datagrid.
|
|
|
|
|
Hi again,
ma se wrote: ...would I still need to convert the value to a decimal where it is being called...
This depends on what you're assigning to. Ultimately the return type is Object even if its a boxed decimal, so unless your assigning to another Object you'd need to cast it. For instance if your paramPound.Value is of type decimal you would have to do this:
paramPound.Value = (decimal)Globals.CheckDecimalForDb(objProperty.Pound)
but this line would throw an invalid cast exception in the instance where you return DBNull.
If paramPound.Value is of type Object, you can leave the cast out, and no exceptions are thrown, but this presumes that paramPound.Value can deal with an object which could either be a boxed decimal or DBNull.
I hope that sort of answers your question...
BTW - I think you are correct to use decimal for currency.
As for the datagrid, I'm afraid I'm unfamiliar with this and have no suggestions.
Rob Philpott.
|
|
|
|
|
Hi again yes,
This how I create my parameter:
SqlParameter paramPound = new SqlParameter("@Pound", SqlDbType.Money, 8);
paramPound.Value = Globals.CheckDecimalForDB(objProperty.Pound);
objCmd.Parameters.Add(paramPound);
I just have 2 questions:
Firstly, because the SQL Server table field is of type money, can I use a decimal? And secondly, with regards to your cast to decimal, it will throw an exception. So the best way to do this is to leave the cast out?
For if you must know, this is my check function:
public static Object CheckDecimalForDB(decimal decCheckDecimal)
{
if(decCheckDecimal != 0)
return decCheckDecimal;
else
return DBNull.Value;
}
How would you do it? Would you just do a test for this when you create your parameters?
Cheers.
|
|
|
|
|
OK. I think you're code is fine as it is.
SqlParameter.Value is of type Object which expects either a DBNull or a value (which is what you give it), and the type SqlDbType.Money is decimal. No casting is necessary.
One point though - this implementation means that a value of 0.00 can't be put into the database. DBNull is used to mean 'not applicable here' not zero. So for instance if you wanted to maintain the balance of a bank account without any funds in it you couldn't. The balance would not be 0.00, the balance would not exist.
Rob Philpott.
|
|
|
|
|
- decimal decEuro = Convert.ToDecimal(txtEuro.Text.Trim()); - would throw an FormatException
- I would say that double would be better for currency
- returned is always object i.e. it is an Object of decimal
- You could look at something like:
System.Globalization.CultureInfo c = new System.Globalization.CultureInfo("en-ZA");//I think?
i don't really know much about this so I can't really help. Or you could format your data in your query before it gets returned to the front end e.g. select convert(varchar(10),DateCaptured,101)... would return me my date already in the format i want
- you could use response.redirect("pageb.aspx?txtFName=" + txtFName.Text + ");
and then at page b you could use Request["txtFName"].ToString();
|
|
|
|
|
Thanks.
I'm still not 100% sure how to format this in the datagrid to the value I want.
|
|
|
|
|
ma se wrote: If I have the following, what is the value of decEuro if the textbox txtEuro is empty? decimal decEuro = Convert.ToDecimal(txtEuro.Text.Trim());
The Visual Studio help file tells you (use MSDN if you don't have Visual Studio) that you will throw an ArgumentException if the value is null, FormatException if "value does not consist of an optional sign followed by a sequence of digits (zero through nine) and an optional decimal point symbol.'
ma se wrote: Is decimal the best data type used for a currency value?
I don't work with currencies, I can't help you there.
ma se wrote: public static Object CheckDecimalForDB(decimal decCheckDecimal)
{
if(decCheckDecimal != 0)
return decCheckDecimal;
else
return DBNull.Value;
}
The datatype/type returned when decCheckDecimal contains a value, is decimal, or Object?
When it contains a value, it will be a decimal. You will need to caste it as such. The proper technique is:
decimal value = (decimal)CheckDecimalFOrDB( d ) as decimal;
if ( value != null ) {
....
}
Again the help file has this documented. Look up 'as operator'.
Can't help you with the Euro Formatting
My suspicion is that you should use the Response.Redirect. The Server.Transfer is performed strictly on the server side, the browser is unaware that it has been directed to a new page. If the user does a refresh, they will be redirected back to the original page.
Response.Redirect causes the browser to request the new page. Values will need to be passed by other means such as a cookie or session state. If session state is used and memory is an issue, be sure to recover the session memory by setting the values to null after you have extracted them.
See the Visual studio help file at ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dv_vbcode/html/vbtskCodeExamplePassingDataFromOneWebPageToAnother.htm
Brian Leach
|
|
|
|
|
Hi guys.I need to build a PlotControl where my graph will be shown but I got no idea how to do it.Maybe anybody an help me with any reference?I would be very grateful
|
|
|
|
|
If you tell me more about your plotboard, do you want to draw it with GUI+, maybe make graphics class, I dont know, send me a mail, I try to help you.
Percy Bloomfield
Santa Cruz - Bolivia
|
|
|
|
|
Is There any way to get the method name inside a method.
ie public int GetName { puts("I'm called from function: GetName" }
|
|
|
|
|
|
Close this window (if you close the mother form, it close all the forms child)
this.Dispose();
_________________
Dispose the cursor
this.Cursor.Dispose();
_________________
Hide this form
this.Hide();
_________________
If title (text) is X: Do X think
if (this.Text == " YOUR TEXT ")
{
THE ACTION THAT YOU WANT THAT THE APPLICATION DOES IF THIS CONDITION IS TRUE
}
else
THE ACTION THAT YOU WANT THAT THE APPLICATION DOES, IF THE CONDITION IS FALSE
_________________
Reset a form
NAME.Text = "";
_________________
Thank you
|
|
|
|
|
What's your question ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I don't know how to put a navigation bar control into the toolbox control, which is the same toolbox in Visual Studio.Net IDE. I'm in dark. Please help me, thanks a lot!
NPS.
|
|
|
|
|
The controls in any Microsoft product tend to be custom written, so they have the edge for a while, then custom control writers make money on selling the 'VS UI' or the 'Office UI' toolkit.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I only know for the .NET Framework v2.0
There is a control which is named
System.Windows.Forms.ToolStripDropDownButton
This control could be added in the control bar.
I recommend to download the Visual Studio 2005 c# express edition beta2 (for free because its a beta).
There is a very good formdesigner in there.
Yours sincerely,
Berni
|
|
|
|
|
Hi,
I have another question, that is regarding to the posting using C#. I am writing an application that is suppose to post data for further processing to another person. I am aware of posting data to the file using file stream. Is there any other mehtod available that data will be carry over ethernet so that I can create another page to retrieve those results. Here is another challenge I am facing, I don;t want to carry that data using URL string. I want that data to be hidden from the user. I am aware of sessions but I have double dimension arrays, and I don't how to use sessions to store the double dimension arrays. I will appreciate any input on this issue. Thanks,
IT specialist
|
|
|
|
|
Hi Guys,
I have another question. I was wondering if there is a way to user Server.Create method that was supported in ASP. Can you please provide me gidance regarding that. I have a dll that happens to work with Server.Create object and it is residing on server. I tried to use that dll as reference in C# web project, but Ihad no luck with it. Now I have decided to use that dll by using Server.Create object. Any help will be appreciated. Thanks,
|
|
|
|
|
Isn't Server.Create for COM objects? If so, just use COM interop.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I've created a class that needs to have a subclass array of the same class, so basically my class contains an array of itself. Does this make sense? What is the best way to go about doing this? Basically I need to make a heirarchy of these classes that can never end
Class
Class1
ClassA
ClassB
Class2
All these classes have the same properties.
Thanks,
JGA
-- modified at 20:49 Monday 24th October, 2005
|
|
|
|
|
You mean an array of class types ? You can't do this, because Class1 cannot derive from ClassA and ClassB, and if it did, this couldn't work when both classA and classB expose the same methods. The obvious thing would be to create an interface, and impliment it in all of these classes, but your class heirarchy would be flat, you could have one base class at most on each level, and they would all impliment the interface in the same way
What are you trying to do ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a todo list heirarchy and each element can have it's own properties (due date, title, priority). so I can have:
Class=
Title:Version 1
DueDate: 12/01/05
Priority: High
SubClass:
Title:Create blah
DueDate: 10/26/05
Priority: High
I'm reading from an XML File to get all of the data, the XML format is something like:
<TODOLIST>
<TASK DUEDATE=10/24/05 TITLE=ASDF PRIORITY=HIGH>
<TASK TITLE=sdfa></TASK>
</TASK>
Does that make sense at all?
|
|
|
|
|
OK - so there's no reason in the world to create a class heirarchy. All you need to do is create a class ( or a struct, more like it ), that contains a reference to itself as a parent and a collection of items that represents it's children ( so you can iterate in either direction ).
So you need one class, like this
class myClass
{
private string title;
private DateTime dueDate;
private PrioryEnum priority; // Create an enum for this
private myClass parent;
private ArrayList children;
}
Then add properties for access as needed.
Christian Graus - Microsoft MVP - C++
|
|
|
|