473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Displaying Stored Procedure results in a textbox

I have a stored procedure which returns a decimal field from a table and i
want my asp.net page to read in the result and then diplay it in a textbox or
a label.

What is the best way to do this?

Nov 19 '05 #1
1 2039
if you are returning a single field, use ExecuteScalar() to get it and
assign the value to your textbox:

sub Page_Load
someTextBox.Text = GetProductAmount(3).ToString()
end sub

public shared function GetProductAmount(productId as integer) as decimal
dim connection as new sqlconnection(connection_String)
dim command as new sqlcommad("SELECT Amount from Price where Id =@id",
connection)
command.parameters.add("@Id", SqlDbType.Int).Value = productId

try
connection.open()
return cdec(command.ExecuteScalar())
finally
connection.dispose()
command.dispoe()
end try
end function
of course you might wanna check for null if that's possible:

dim o as object = command.ExecuteScalar()
if not o is nothing andalso not o is DbNull.Value then
return cdec(o)
end if
return 0.0

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"neil_pat" <ne*****@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
I have a stored procedure which returns a decimal field from a table and i
want my asp.net page to read in the result and then diplay it in a textbox or a label.

What is the best way to do this?

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eva | last post by:
Hi I have 2 comboboxes on my form that gathers 2 parameters: The Caravan_Name and the caravan_Length. these 2 values that the user selects are placed into a stored procedure as parameters. The...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
7
by: Peter D.C. | last post by:
Hi I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL...
22
by: M K | last post by:
Heres my SP: ( i am trying to add more than 1 field but get the same error no matter how many i try to add, i thought i would try to insert the primary key only and work up from there but the...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
12
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that...
2
by: gayano | last post by:
Hi all, I need help with Sql Stored Procedure, I have two fields in a table Table named "User" Field1 named "FirstName" Field2 named "LastName" I need to give a chance to user to search...
4
by: gayano | last post by:
Hi I'm Tried Lot's of forums but still no Answer Can you guys help me? What i have is a Stored procedure looks like this ALTER PROCEDURE dbo.DriveSearch @Driver varchar(50) AS SELECT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.