473,385 Members | 1,875 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,385 software developers and data experts.

Application->SP problem

Hi,

I use ASP.NET/C#/MS SQL and I'm trying to do the following but I find it
very hard!
I have Stored Procedure which saves data from the Application into DataBase.
One of its parameters is @Rooms INT. When A user insert in the WebForm a
value everything is allright because I do this:

cmd.Parameters.Add(new SqlParameter("@ROOMS", SqlDbType.Int));
cmd.Parameters["@ROOMS"].Value = Int32.Parse(RoomsTB.Text.Trim());
where cmd is SqlCommand and RoomsTB is the TextBox from where I take the
value.

When the user doesn't insert value in the TextBox there is an error because
the Stored Procedure doesn't receive value for the Parameter @ROOMS. How
could I send to the SP NULL for this parameter when there isn't value in the
TextBox?

Thank you in advance!

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.
Nov 16 '05 #1
2 1082
Hi, Viktor!

On your stored procedure, try assigning the @Rooms parameter with a 0 value.

For example,
create procedure yourProcedure
(
@rooms = 0
)
....

If in case you execute your procedure, you may or may not provide the value
for the @rooms parameter

- OR -

Try to test the value of RoomsTB.Text.Trim() before you pass this value to
your SqlCommand parameter value.

For example
if (RoomsTB.Text.Trim() != null)
cmd.Parameters["@Rooms"].Value = Int32.Parse(RoomsTB.Text.Trim());
else
cmd.Parameters["@Rooms"].Value = 0;

Hope this helps!

--Ann :)

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

I use ASP.NET/C#/MS SQL and I'm trying to do the following but I find it
very hard!
I have Stored Procedure which saves data from the Application into DataBase. One of its parameters is @Rooms INT. When A user insert in the WebForm a
value everything is allright because I do this:

cmd.Parameters.Add(new SqlParameter("@ROOMS", SqlDbType.Int));
cmd.Parameters["@ROOMS"].Value = Int32.Parse(RoomsTB.Text.Trim());
where cmd is SqlCommand and RoomsTB is the TextBox from where I take the
value.

When the user doesn't insert value in the TextBox there is an error because the Stored Procedure doesn't receive value for the Parameter @ROOMS. How
could I send to the SP NULL for this parameter when there isn't value in the TextBox?

Thank you in advance!

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.

Nov 16 '05 #2
Thanks for the reply, but I'd like to save in DataBase NULL instead of 0.

Viktor


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.729 / Virus Database: 484 - Release Date: 27.7.2004 a.
Nov 16 '05 #3

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

Similar topics

7
by: Job Lot | last post by:
How can I terminate console application in Try…Catch…Finally…End Try block so that code in Finally gets executed. If I use End statement Finally does not get executed. Following is my code...
1
by: Sean | last post by:
Hi, I have a problem running my application. When I run my application, the window program starts as being minimized on the taskbar and the worst thing is that I can't even maximize or put it...
1
by: WStoreyII | last post by:
When i try to make a new web application project i keep getting the following error: Visual Studio.Net cannot create or open the application. The likeliest problem is that requiered components...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
5
by: Michael G. | last post by:
Hello! We developed a small application using VS2005/ASP.NET 2. On development station it worked well. Then we published the site to a directory on the development. comp., and brought to the...
2
by: CWogksch | last post by:
Hello, Everyone... My name is Chris Wogksch. I have a point of sale application developed in VB6 using MS Access 2003 as the database. I've been running versions of this app for over eight...
3
by: noisefree | last post by:
Hello, I have a problem on an application I am developing: This C# Windows Application calls a C# Web Service, which it uses the SourceSafeTypeLib DLL to interact with Visual Source Safe 6. ...
1
by: noisefree | last post by:
Hello, I have a problem on an application I am developing: This C# Windows Application calls a C# Web Service, which it uses the SourceSafeTypeLib DLL to interact with Visual Source Safe 6. ...
1
by: bradwest1217 | last post by:
I am having a problem running a server command line executable from my web application. What is happening is I cannot make a database connection using the command line application (written in...
1
by: vijayakumar | last post by:
hi all I'm beginner in CORBA Server-Client application development. My server- client application was worked well and i have tested it too. Due to some Network problem we have rebooted our...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.