469,647 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

string Truncated error

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

Jul 22 '05 #1
3 1558
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" <sp*******@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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

Jul 22 '05 #2
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.
Jul 22 '05 #3
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

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Gaurav | last post: by
1 post views Thread by Dino Nardini | last post: by
1 post views Thread by Bernie Yaeger | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.