For Programmers: Free Programming Magazines  


Home > Archive > ASP > March 2005 > string Truncated error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author string Truncated error
Chumley Walrus

2005-03-22, 3:55 pm

I'm getting a "string could be truncated" error at the line where my
strSql is executed ( my_conn.Execute (strSql) ), but it doesnt happen
all the time, just periodically. I used to have this pointing to an
Access db, but I changed it over to Sql, getting rid of the # datetime
delimiters and replacing with ' . Wondering if the first StrSql string
in the if statement if too long:

'''''''''''''''''''''''''''
Function ChkString(string)
if string = "" then string = " "
ChkString = Replace(string, "'", "''")
End Function

set my_conn= Server.CreateObject("ADODB.Connection")
my_Conn.Open DBCon

' Check to see if it's a new record to be added or an old one to
update
StrSql= "Select * from diary where dte = '" & Request("view_Date") &
"'"
set rs = my_conn.Execute (StrSql)

if rs.BOF or rs.EOF then ' No records found. i.e. New record
StrSql ="INSERT INTO diary (dte, text_field) values ('" &
request("view_date") & "', '" & chkString(request("txt")) & "')"
else ' Record found. i.e. update record.
StrSql = "UPDATE diary SET diary.dte = '" & request("view_date") & "',
text_field = '" & chkString(request("txt")) & "' WHERE id = " &
rs("id")
End If

my_conn.Execute (strSql)

'''''''''''

thanks
chumley

Aaron [SQL Server MVP]

2005-03-22, 3:55 pm

Well, what is the table definition (e.g. datatype and length of
"text_field" - which is an awful, awful name for a column, by the way)?

--
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.




"Chumley Walrus" <springb2k@yahoo.com> wrote in message
news:1111517588.706841.242270@z14g2000cwz.googlegroups.com...
> I'm getting a "string could be truncated" error at the line where my
> strSql is executed ( my_conn.Execute (strSql) ), but it doesnt happen
> all the time, just periodically. I used to have this pointing to an
> Access db, but I changed it over to Sql, getting rid of the # datetime
> delimiters and replacing with ' . Wondering if the first StrSql string
> in the if statement if too long:
>
> '''''''''''''''''''''''''''
> Function ChkString(string)
> if string = "" then string = " "
> ChkString = Replace(string, "'", "''")
> End Function
>
> set my_conn= Server.CreateObject("ADODB.Connection")
> my_Conn.Open DBCon
>
> ' Check to see if it's a new record to be added or an old one to
> update
> StrSql= "Select * from diary where dte = '" & Request("view_Date") &
> "'"
> set rs = my_conn.Execute (StrSql)
>
> if rs.BOF or rs.EOF then ' No records found. i.e. New record
> StrSql ="INSERT INTO diary (dte, text_field) values ('" &
> request("view_date") & "', '" & chkString(request("txt")) & "')"
> else ' Record found. i.e. update record.
> StrSql = "UPDATE diary SET diary.dte = '" & request("view_date") & "',
> text_field = '" & chkString(request("txt")) & "' WHERE id = " &
> rs("id")
> End If
>
> my_conn.Execute (strSql)
>
> '''''''''''
>
> thanks
> chumley
>



Dave Anderson

2005-03-22, 8:55 pm

Chumley Walrus wrote:
> I'm getting a "string could be truncated" error at the line where my
> strSql is executed ( my_conn.Execute (strSql) ), but it doesnt happen
> all the time, just periodically...


Are you using POST or GET for your form method? Using request("txt") is
ambiguous.

> ...StrSql ="INSERT INTO diary (dte, text_field) values ('" &
> request("view_date") & "', '" & chkString(request("txt"))...



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Ganesh

2005-03-23, 3:55 pm

Hi,

This error happens when the data that you try to update or insert in the
table is more than what the field can handle. For ex: a varchar(20) string
cannot hold more than 20 characters. So you will get the error when you pass
a string to this field which is more than 20.

Ganesh

"Chumley Walrus" wrote:

> I'm getting a "string could be truncated" error at the line where my
> strSql is executed ( my_conn.Execute (strSql) ), but it doesnt happen
> all the time, just periodically. I used to have this pointing to an
> Access db, but I changed it over to Sql, getting rid of the # datetime
> delimiters and replacing with ' . Wondering if the first StrSql string
> in the if statement if too long:
>
> '''''''''''''''''''''''''''
> Function ChkString(string)
> if string = "" then string = " "
> ChkString = Replace(string, "'", "''")
> End Function
>
> set my_conn= Server.CreateObject("ADODB.Connection")
> my_Conn.Open DBCon
>
> ' Check to see if it's a new record to be added or an old one to
> update
> StrSql= "Select * from diary where dte = '" & Request("view_Date") &
> "'"
> set rs = my_conn.Execute (StrSql)
>
> if rs.BOF or rs.EOF then ' No records found. i.e. New record
> StrSql ="INSERT INTO diary (dte, text_field) values ('" &
> request("view_date") & "', '" & chkString(request("txt")) & "')"
> else ' Record found. i.e. update record.
> StrSql = "UPDATE diary SET diary.dte = '" & request("view_date") & "',
> text_field = '" & chkString(request("txt")) & "' WHERE id = " &
> rs("id")
> End If
>
> my_conn.Execute (strSql)
>
> '''''''''''
>
> thanks
> chumley
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com