|
 |
asp_databases thread: Getting a number out of a TextStream
Message #1 by taradawnhull@y... on Tue, 20 Feb 2001 17:19:21
|
|
I am trying to update a database by reading the records out of a text file
but when I go to read numbers there is as type mismatch when I try to
update that field in the database which is a number field but the data I
have is a string.....how do I convert the data that is in string format
(that is from the text file) into a number so that it can be inserted into
a access database number field?
Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 20 Feb 2001 20:56:20 +0100
|
|
Depending on the type you want to convert to, you can try this:
If IsNumeric(sMyString) then ' check to see if you can convert
sMyString = CInt(sMyString) ' convert to int or
' sMyString = CLng(sMyString) ' Convert to long
end if
If this doesn't work, I suggest you post some code. Usually you should just
be able to pass a string that contains a valid number, and let the database
handle the conversion.
Imar
At 05:19 PM 2/20/2001 +0000, you wrote:
>I am trying to update a database by reading the records out of a text file
>but when I go to read numbers there is as type mismatch when I try to
>update that field in the database which is a number field but the data I
>have is a string.....how do I convert the data that is in string format
>(that is from the text file) into a number so that it can be inserted into
>a access database number field?
Message #3 by Quang Tran <qtran@i...> on Tue, 20 Feb 2001 14:28:22 -0500
|
|
Read java.lang for two class String and Integer. These class help you to
convert from number to string and vice versa
-----Original Message-----
From: taradawnhull@y... [mailto:taradawnhull@y...]
Sent: Tuesday, February 20, 2001 12:19 PM
To: ASP Databases
Subject: [asp_databases] Getting a number out of a TextStream
I am trying to update a database by reading the records out of a text file
but when I go to read numbers there is as type mismatch when I try to
update that field in the database which is a number field but the data I
have is a string.....how do I convert the data that is in string format
(that is from the text file) into a number so that it can be inserted into
a access database number field?
Message #4 by John Pirkey <mailjohnny101@y...> on Tue, 20 Feb 2001 11:35:26 -0800 (PST)
|
|
Dont supply the tic marks around the value when you build your sql string. or, to
be extra sure - use the CInt (or CDbl or CSng, depending on the data) to convert it
to that data type.
for example:
sql = "UPDATE Table SET "
sql = sql & "StringField = '" & variable & "', "
sql = sql & "IntegerField = " & variable & ", "
sql = sql & "WHERE RowID = " & lrowid
john
--- taradawnhull@y... wrote:
> I am trying to update a database by reading the records out of a text file
> but when I go to read numbers there is as type mismatch when I try to
> update that field in the database which is a number field but the data I
> have is a string.....how do I convert the data that is in string format
> (that is from the text file) into a number so that it can be inserted into
> a access database number field?
>
> ---
> Please take a moment to tell us how you are using AuthentiX, WebQuota, and
> VideoQuota
>
> http://www.flicks.com/feedback/feed.asp
>
> Scott Gordon
> Marketing
> Flicks Software
> www.flicks.com
> xxx-xxx-xxxx
>
John Pirkey
MCSD
John@S...
http://www.stlvbug.org
Message #5 by Tara Hull <taradawnhull@y...> on Tue, 20 Feb 2001 21:49:57 -0800 (PST)
|
|
I tried using CDbl but it type mismatch still....here
is the code:
strPaid=(RIGHT(strSH_CH_PD, 9))
strPaid = CDbl(strPaid)
strLJS_PD_NO_AM=LEFT(strPartB, 26)
strDatePd=LEFT(strLJS_PD_NO_AM,10)
strChkAm=RIGHT(strLJS_PD_NO_AM, 9)
RESPONSE.WRITE strPronum
SET
objCONN=SERVER.CREATEOBJECT("ADODB.CONNECTION")
objCONN.OPEN "DSN=D30017289-probills;Uid=;Pwd=;"
Set rsItem
Server.CreateObject("ADODB.Recordset")
rsItem.Open "probills", objConn,
adOpenForwardOnly, adLockOptimistic, adCmdTable
rsItem.AddNew
rsItem("pronum") = strPronum
rsItem("blnum") = strBlnum
rsItem("canum") = strCanum
rsItem("clinum") = strClinum
rsItem("prodate") = strProdate
rsItem("casort") = strCasort
rsItem("shipper") = strShipper
rsItem("charged") = strCharged
rsItem("paid") = strPaid
rsItem("dateljspd") = strDatePd
rsItem("ljschecknu") = strChkNo
rsItem("ljscheckam") = strChkAm
rsItem.Update
LOOP
objFileTextStream.CLOSE
rsItem.Close
Set rsItem = Nothing
--- Imar Spaanjaars <Imar@S...> wrote:
> Depending on the type you want to convert to, you
> can try this:
>
> If IsNumeric(sMyString) then ' check to see if you
> can convert
> sMyString = CInt(sMyString) ' convert to
> int or
> ' sMyString = CLng(sMyString) ' Convert
> to long
> end if
>
> If this doesn't work, I suggest you post some code.
> Usually you should just
> be able to pass a string that contains a valid
> number, and let the database
> handle the conversion.
>
> Imar
>
>
>
>
> At 05:19 PM 2/20/2001 +0000, you wrote:
> >I am trying to update a database by reading the
> records out of a text file
> >but when I go to read numbers there is as type
> mismatch when I try to
> >update that field in the database which is a number
> field but the data I
> >have is a string.....how do I convert the data that
> is in string format
> >(that is from the text file) into a number so that
> it can be inserted into
> >a access database number field?
>
>
>
Tara Dawn Hull
Greenberg & Associates
MicroComputer Programmer/Application Developer
Mobile/Voicemail/Pager: (xxx)xxx-xxxx
Home: (xxx) xxx-xxxx
Fax: (xxx) xxx-xxxx
Message #6 by Imar Spaanjaars <Imar@S...> on Wed, 21 Feb 2001 07:39:52 +0100
|
|
Take a look here: http://www.adopenstatic.com/faq/800a0bb9step2.asp
It could be possible that you didn't define adOpenForwardOnly etc
HtH
Imar
At 09:49 PM 2/20/2001 -0800, you wrote:
>I tried using CDbl but it type mismatch still....here
>is the code:
>
>strPaid=(RIGHT(strSH_CH_PD, 9))
> strPaid = CDbl(strPaid)
> strLJS_PD_NO_AM=LEFT(strPartB, 26)
> strDatePd=LEFT(strLJS_PD_NO_AM,10)
> strChkAm=RIGHT(strLJS_PD_NO_AM, 9)
>
>
>
> RESPONSE.WRITE strPronum
>
>
>
> SET
>objCONN=SERVER.CREATEOBJECT("ADODB.CONNECTION")
>
> objCONN.OPEN "DSN=D30017289-probills;Uid=;Pwd=;"
>
> Set rsItem
>Server.CreateObject("ADODB.Recordset")
> rsItem.Open "probills", objConn,
>adOpenForwardOnly, adLockOptimistic, adCmdTable
>
> rsItem.AddNew
>
> rsItem("pronum") = strPronum
> rsItem("blnum") = strBlnum
> rsItem("canum") = strCanum
> rsItem("clinum") = strClinum
> rsItem("prodate") = strProdate
> rsItem("casort") = strCasort
> rsItem("shipper") = strShipper
> rsItem("charged") = strCharged
> rsItem("paid") = strPaid
>
> rsItem("dateljspd") = strDatePd
> rsItem("ljschecknu") = strChkNo
> rsItem("ljscheckam") = strChkAm
>
> rsItem.Update
> LOOP
>
> objFileTextStream.CLOSE
>
> rsItem.Close
> Set rsItem = Nothing
Message #7 by "Ken Schaefer" <ken@a...> on Wed, 21 Feb 2001 17:48:43 +1100
|
|
Tara,
Can you please post:
a) The exact error number and error message that you are getting
b) The line number where the error is occuring (please mark it in your code)
c) A Response.Write() of the variable that is causing the error, for
example, if you do this:
strPaid = "SomeText"
strPaid = CLng(strPaid)
of course you are going to get a type mismatch error - because you can cast
"sometext" as a long numeric.
Cheers
Ken
----- Original Message -----
From: "Tara Hull" <taradawnhull@y...>
To: "ASP Databases" <asp_databases@p...>
Sent: Wednesday, February 21, 2001 4:49 PM
Subject: [asp_databases] Re: Getting a number out of a TextStream
> I tried using CDbl but it type mismatch still....here
> is the code:
>
> strPaid=(RIGHT(strSH_CH_PD, 9))
> strPaid = CDbl(strPaid)
> strLJS_PD_NO_AM=LEFT(strPartB, 26)
> strDatePd=LEFT(strLJS_PD_NO_AM,10)
> strChkAm=RIGHT(strLJS_PD_NO_AM, 9)
>
>
>
> RESPONSE.WRITE strPronum
>
>
>
> SET
> objCONN=SERVER.CREATEOBJECT("ADODB.CONNECTION")
>
> objCONN.OPEN "DSN=D30017289-probills;Uid=;Pwd=;"
>
> Set rsItem
> Server.CreateObject("ADODB.Recordset")
> rsItem.Open "probills", objConn,
> adOpenForwardOnly, adLockOptimistic, adCmdTable
>
> rsItem.AddNew
>
> rsItem("pronum") = strPronum
> rsItem("blnum") = strBlnum
> rsItem("canum") = strCanum
> rsItem("clinum") = strClinum
> rsItem("prodate") = strProdate
> rsItem("casort") = strCasort
> rsItem("shipper") = strShipper
> rsItem("charged") = strCharged
> rsItem("paid") = strPaid
>
> rsItem("dateljspd") = strDatePd
> rsItem("ljschecknu") = strChkNo
> rsItem("ljscheckam") = strChkAm
>
> rsItem.Update
> LOOP
>
> objFileTextStream.CLOSE
>
> rsItem.Close
> Set rsItem = Nothing
>
|
|
 |