Home All Groups Group Topic Archive Search About
Author
22 Mar 2005 6:53 PM
Chumley Walrus
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

Author
22 Mar 2005 7:10 PM
Aaron [SQL Server MVP]
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.




Show quoteHide quote
"Chumley Walrus" <spring***@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
>
Are all your drivers up to date? click for free checkup

Author
22 Mar 2005 7:29 PM
Dave Anderson
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.

Show quoteHide quote
> ...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.
Author
23 Mar 2005 1:43 PM
Ganesh
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

Show quoteHide quote
"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
>
>

Bookmark and Share