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

StoredProcedure -> Value from the Application

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 18 '05 #1
2 944
Viktor,

You have a number of choices here:

1. Use a required field validator (and probably a range validator to make
certain the input is a number). This way a user has to fill in the field.
2. Set your database to accept nulls in the given field. Check if the field
contains a value. If it doesn't don't add the parameter.

if (RoomsTB.Text.Trim() != "")
{
cmd.Parameters.Add(new SqlParameter("@ROOMS", SqlDbType.Int));
cmd.Parameters["@ROOMS"].Value = Int32.Parse(RoomsTB.Text.Trim();
}
3. If the text box is empt assign it an integer that won't be used otherwise
such as a zero.

if (RoomsTB.Text.Trim() == "")
{
cmd.Parameters.Add(new SqlParameter("@ROOMS", SqlDbType.Int));
cmd.Parameters["@ROOMS"].Value =0
}
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:ek**************@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 18 '05 #2
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:ek**************@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?


Try this (untested):

string roomsTrimmed = RoomsTB.Text.Trim();
if (roomsTrimmed.Length != 0)
{
cmd.Parameters["@ROOMS"].Value = Int32.Parse(roomsTrimmed);
}
else
{
cmd.Parameters["@ROOMS"].Value = DBNull.Value;
}
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3

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

Similar topics

10
by: Heiko Pliefke | last post by:
Hi NG! I wrote a stored procedure which at first deletes 100.000 rows and then inserts 100.000 new rows. There is a huge difference between executing this SP in the query-analyzer (runtime...
1
by: Lauren Quantrell | last post by:
Shouldn't this work in MS Access2000? What am I doing wrong? Any help is appreciated. lq Function TestADOStoredProcedure() Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim myExtract...
3
by: Sabari | last post by:
Hi, I have a SQL Stored Procedure that has 20 to 25 parameters to be passed.I run into problems when i assign wrong valuse to parameters.I have heard that it is possible to debug SQL...
2
by: anoopgopal007 | last post by:
Hi friends... I have one problem... I am using C#, and CrystalReport9. In my project I used StoredProcedure with one input parameter. ...
1
by: baburk | last post by:
Hi All, We all are creating Select statement both in View and StoredProcedure In view it virtually links to tables. What is the difference. Thanks in advance
1
by: phanimadhav | last post by:
Hello friends,I have one small doubt.Acually myclient asking by using tableAdapetr call the MySQL procedures.How to call the MySQL storedprocedure in TableAdapter.In the Table adapter contain one...
2
by: Tony Johansson | last post by:
Hello! I just wonder when you use StoredProcedure will you then use DataSet ? In the example that I have seen is the DataSet not used is this normal ? //Tony
1
by: Tony Johansson | last post by:
Hello! Is it possible to use a StoredProcedure when you have SqlDataAdapter or is it only possible when you have SqlCommand like SqlCommand thisCommand = myConnection.CreateCommand;...
0
by: shivakrishna | last post by:
hi i am having 50 storedprocedures , i want know the names of tables and views used in the storedprocedure so can any one help me in this regard
1
by: shivakrishna | last post by:
how to get the list of all tables and views used in storedprocedure can any one help in this issue
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.