473,499 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1643
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10763
by: Gaurav | last post by:
Hello, I am using visual c++ 6 and i am having problems with string to work. ******** Here is the program project.cpp********* #include <iostream.h> #include <string> #include "stdafx.h"
3
3369
by: David Sharp | last post by:
I'm working with some long standing VB/SQL Server applications and for the second time we've suffered from having the parameters to a stored procedure call get silently truncated now that the data...
3
40167
by: RDRaider | last post by:
How can I find which record(s) cause this error: Server: Msg 8152, Level 16, State 9, Line 1 String or binary data would be truncated. The statement has been terminated. I have tried Profiler...
7
10610
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
1
3679
by: Dino Nardini | last post by:
Hey folks, I've been migrating a content management system from MS SQL Server 7 over to PostgreSQL. I used the EMS DataPump utility (http://www.ems-hitech.com/index.phtml) to migrate the...
1
2789
by: Bernie Yaeger | last post by:
What causes the error 'string or binary data would be truncated'? Here's the routine that sometimes causes the error, sometimes not: irow("ctotal") = FormatCurrency(irow("total"), 2,...
7
43835
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
7
17686
Coldfire
by: Coldfire | last post by:
i am having error ....details are ASP.Net application...in which I have a textbox <asp:TextBox ID="Other" TextMode=SingleLine CssClass="serviceBox" Width="250" Height="45" Runat="server"...
15
5178
geolemon
by: geolemon | last post by:
I'm having a seriously Twilight Zone moment: In the code below, I'm building a SQL command into a string variable, declared at the top of my code. Then, I connect to the database and try to...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.