473,385 Members | 1,830 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.

Problem updating an integer value in SQL Server table from ASP.NET page

Hey Guys,

Hoping someone can help me here - I am at my wits end trying to get this to work.

I have written a stored procedure in SQL Server to move records from one table to another once verified, and then update two fields.

The first field is a varchar field which updates without a hitch.

However, the second is an integer field (type smallint) and despite having this declared in my ASP VB.NET code and in SQL server it refuses to update.

If I put a fixed value in the update statement it works, so I am assuming there is a type conversion issue somewhere.

Here is my value assignment in VB.NET:

Expand|Select|Wrap|Line Numbers
  1. smallPcs = Int(Pcs.Text)
  2. cmd.Parameters.Add("@ShipQty", SqlDbType.SmallInt).Value = smallPcs
  3.  
This is done as the value is typed into a text field (verification is done to make sure only numbers are entered).

The stored procedure when launched executes these two update queries.

The first one works, but the second one fails (no error is returned):

Expand|Select|Wrap|Line Numbers
  1.     DECLARE @UPD nvarchar(1000)
  2.     SET @UPD = 'UPDATE NewInvoice '
  3.     SET @UPD = @UPD + 'SET ShipmentRef = ' + @ImportFile
  4.     SET @UPD = @UPD + ' WHERE InvoiceNbr = ' + @Invoice
  5.     EXEC sp_executesql @UPD
  6.     SET @UPD = 'UPDATE NewInvoice '
  7.     SET @UPD = @UPD + 'SET TotalPcs = ' + @ShipQty
  8.     SET @UPD = @UPD + ' WHERE InvoiceNbr = ' + @Invoice
  9.     EXEC sp_executesql @UPD
  10.  
I have tried everything I can think of now - anyone else any ideas?
Aug 24 '09 #1

✓ answered by shanef1981

Don't worry - I finally figured it out.

I converted the value to a varchar to see if it would evaluate it properly then, and hey presto! it did...

Expand|Select|Wrap|Line Numbers
  1. SET @UPD = @UPD + 'SET TotalPcs = ' + convert(varchar(5), @ShipQty)
  2.  
This seems to have fixed it.

2 3659
Don't worry - I finally figured it out.

I converted the value to a varchar to see if it would evaluate it properly then, and hey presto! it did...

Expand|Select|Wrap|Line Numbers
  1. SET @UPD = @UPD + 'SET TotalPcs = ' + convert(varchar(5), @ShipQty)
  2.  
This seems to have fixed it.
Aug 24 '09 #2
jhardman
3,406 Expert 2GB
Hey Shane, welcome to Bytes. You accidentally posted in the "ASP Classic (VBScript)" forum. I've moved your question to the ASP.NET forum, but I see you already figured it out. Just remember that everything posted over HTTP is considered text even if it only contains numbers, so you will need to deal with that one way or another on the backend. And in the future, please post ASP.NET questions in the ASP.NET forum.

Jared
Aug 25 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
10
by: Brian Henry | last post by:
Hi, I am having a problem with an attachment system I made... it works with files up to ~3MB in size then after that if you try to upload a file it just goes to a "Page can not be displayed" page...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
4
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event....
1
by: r2destini | last post by:
Hi Friends, I am new to .Net. So I don't know much. I am facing a problem in updating database through ADO.Net I am creating the dataset and there is no problem in the updation and...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
2
by: toddw607 | last post by:
Hi Everyone! I have a ASP.NET webform that brings data in from SQL Server 2000 and displays it on a page. I want to update the webpage while in IE using the following code: <%@ Import...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
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...
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...

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.