Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Aug 2009
Posts: 2
#1: Aug 24 '09
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?
best answer - posted 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.
Newbie
 
Join Date: Aug 2009
Posts: 2
#2: Aug 24 '09

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


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.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Aug 25 '09

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


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
Reply