Wrox Programmer Forums
|
Classic ASP Components Discussions specific to components in ASP 3.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Components section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2008, 03:35 AM
Registered User
 
Join Date: Mar 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to insert varchar data in numeric column

hi,
I have taken a value from column which is of varchar type, and want to insert this value into another column which is of numeric type.
It is showing error.. how can i solve this..please help me out.
The code is :--
<%
Dim conn,productprice
Dim sql
Dim rs,rs1
transactionId=loginname+"01"
set conn = server.createobject("ADODB.Connection")
conn.open "Provider=SQLOLEDB;DATA SOURCE=RAJNEESHR;UID=sa;DATABASE=shop"
set rs1=Server.CreateObject("ADODB.Recordset")
set rs = Server.CreateObject("ADODB.Recordset")

sql="select Product_id,P_name,loginname,P_price from productInfo group by loginname,Product_id,P_name,P_price having loginname='"&loginname&"'"


rs.Open sql, conn

 DO WHILE NOT rs.EOF
productprice=rs("P_price")

' Here rs("P_price") is varchar

sqlInsert="insert into transactions(Transaction_Id,Transaction_Amout,Tran saction_Date,Product_Name,Status,Email) values ('"& transactionId &"', '& productprice &' ,'"&Date&"','"&rs("Product_id")&"','Shipped','"&lo ginname&"')"

conn.execute sqlInsert

rs.MoveNext
Loop
%>

Dhiraj
 
Old March 31st, 2008, 05:58 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

If data in the p_price field is non numeric for any one record and you try to insert this data in second table, you will get error.

Before inserting the data check whether it is numeric or not.

Example:

if isnumeric(productprice) then
    sqlInsert="insert into ..."
    conn.execute sqlInsert
end if

Om Prakash
 
Old March 31st, 2008, 06:01 AM
Registered User
 
Join Date: Mar 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the column of that table is varchar, but they have stored number in it. The field name is price and datatype is varchar. so how can i do.

Dhiraj
 
Old March 31st, 2008, 06:23 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

In this case above code should work

Om Prakash





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is maxium size of varchar data type is 8000? kawrat SQL Server 2000 7 February 5th, 2007 04:08 AM
column with one character - use Char or Varchar crmpicco MySQL 4 January 17th, 2006 07:35 AM
Data type change from int to Varchar getxyz SQL Server 2000 1 April 29th, 2005 09:59 AM
Calculating "Sum" of Numeric values in Varchar fld itHighway Classic ASP Basics 6 December 29th, 2004 07:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.