Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Monday, March 12, 2012

Monitoring Database hits

In any asp.net application, whats the simplest way to monitor how many times a page hits the database (opens and closes a connection)?

JontyMC:

In any asp.net application, whats the simplest way to monitor how many times a page hits the database (opens and closes a connection)?

If you are using a data access layer, you can write some code to log when the data is connection/executed. You can log this to a text file, or a database, or any other external data source.

Monday, February 20, 2012

Money in SQL and ASP.NET

Hi,
I'm having some trouble with my asp.net page and my sql database. What I'm trying to do is allow the user to upload an number to the database, the number is a money amount like 2.00 (£2.00) or 20.00(£20.00). I've tried using money and smallmoney datatypes but the numbers usually end up looking like this in the database...
I enter 2.00 and in the database it looks like 2.00000, and even if I enter the information directly into the database I get the same results. I'm not going to be using big numbers with lots of decimal places like this 1000,000,0000. Can anyone help me? All I want is to know what to set the value to on my aspx page and what setting to set the field to in my database, I'd just like two pound to appear as 2.00. any help would be great.

I'm using Microsoft Visual Web Developer 2005 Express Edition and Microsoft SQL Server 2005 if that helps.


Thanks.

Hi,

The money or smallmoney datatypes are the right ones to use in your case. By design, they have four decimal at the end and you can find relevent infromation related to these two from Books Online. As to your question, you use either of these types in your database to hold your data and when it is time to show your data on your asp.net page, you can format them into what you need. For example, {0,c2} will give you two decimals as you want. In GridView:

<asp:BoundField HeaderText="Price/Unit" DataField="UnitPrice" DataFormatString="{0:c2}"HtmlEncode="false"> </asp:BoundField>

Or

<asp:TemplateFieldHeaderText="UnitPrice"><ItemTemplate><asp:LabelID="Label2"runat="server"Text='<%# Eval("UnitPrice","{0:c2}") %>'></asp:Label></ItemTemplate></asp:TemplateField>|||

Hi,

You don't say what type of controls you're trying to display this in. However, one simple way (that I think you can apply to any text box or label control) is this:

TextBox1.Text = (512.23).ToString("c")

If you need to set the page to a different currency than your own, one way is to set the UICulture of the page directive:

<%@. Page Language="VB" AutoEventWireup="false" UICulture="en-GB" CodeFile="Default4.aspx.vb" Inherits="Default4" %>
You can also set this in the web.config file (under globalization)
How the numbers are stored in SQL aren't relevant to how they'll be displayed - as you've discovered!
Hope this helps.
Paul

Money format error

I use asp.net 2.0 and sql server 2005 for a web site (and Microsoft enterprise library).When I run aplication at local there is no problem but at the server I take this error:

Disallowed implicit conversion from data type varchar to data type money, table 'dbname.dbo.shopProducts', column 'productPrice'. Use the CONVERT function to run this query.

productPrice coloumn format is money. It was working correctly my old server but now it crashed.How can I solve this problem? And why it isn't work same configuration?

My code:

decimal productPrice;

Database db =DatabaseFactory.CreateDatabase("connection");

string sqlCommand ="update shopProducts set .................,productPrice='" + productPrice.ToString().Replace(",",".") +"',................where productID=" + productID +" ";

db.ExecuteNonQuery(CommandType.Text, sqlCommand)

Decimal should be able to covert to SqlMoney implicitly, why you convert the price to string before update it to the table? However, it's better to useParameterized Queries as possible as you can.

money datatype

i have money a datatype in my table and it allows null
value. If i try to enter a null value from my asp page i
am getting error... what i need to do on my sql server
table so it does not error me out. i think, it has
something to do with precision and scale... but I don't
know what.
ERROR:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1:
Incorrect syntax near ','.
ThanksCould you display the string that you are constructing in your application?
Look at this string when the money column is null. I am sure you will know
what's causing the problem. It just looks like you are concatenating
something with NULL and the whole thing becomes NULL.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
What hardware is your SQL Server running on?
http://vyaskn.tripod.com/poll.htm
"eren" <oeren@.calcoastcu.org> wrote in message
news:004c01c37d37$d3bd55e0$a401280a@.phx.gbl...
i have money a datatype in my table and it allows null
value. If i try to enter a null value from my asp page i
am getting error... what i need to do on my sql server
table so it does not error me out. i think, it has
something to do with precision and scale... but I don't
know what.
ERROR:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1:
Incorrect syntax near ','.
Thanks|||This looks like a syntax error in the statement generated by the asp page.
Verify that the statement is correct and that nulls are handled correctly by
the asp code generating the statement.
Shaun
"eren" <oeren@.calcoastcu.org> wrote in message
news:004c01c37d37$d3bd55e0$a401280a@.phx.gbl...
> i have money a datatype in my table and it allows null
> value. If i try to enter a null value from my asp page i
> am getting error... what i need to do on my sql server
> table so it does not error me out. i think, it has
> something to do with precision and scale... but I don't
> know what.
> ERROR:
> Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
> [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1:
> Incorrect syntax near ','.
> Thanks