473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

String or binary data would be truncated. The statement has been terminated

22
I'll trying to update some information, the data that i want to update its also came from same sql database, and that error showing . thanks in advance
Attached Files
File Type: txt help.txt (596 Bytes, 279 views)
Apr 2 '14 #1

✓ answered by mcupito

You really haven't given us much to go on. You should really add Parameters when dealing with a database.

See my code for an example:

Expand|Select|Wrap|Line Numbers
  1.         Dim conn As New SqlConnection("Data Source=SQLTEST_HR,4000\SQLEXPRESS;Integrated Security=True")
  2.         Dim cmd As New SqlCommand
  3.  
  4.         'insert statement
  5.         cmd.CommandText &= " INSERT INTO ELECT_SALARY_DFRL (ELECT_XREF_SEQ_ID, EMPL_SALARY_DFRL_AMT, EMPL_SALARY_DFRL_FREQ_CD, "
  6.         cmd.CommandText &= "  FUND_SEQ_ID, ELECT_SALARY_DFRL_FUND_PCT_RT, ELECT_SALARY_DFRL_ELECT_DT, BEG_DT, END_DT)"
  7.         cmd.CommandText &= " VALUES (@SeqID, @DefAmt, @Freq, @FundID, @FundPct, @Today, @BegDT, @EndDT); "
  8.  
  9.         ' parameters for sql insert, from DGV
  10.         cmd.Parameters.AddWithValue("@SeqID", empseqId)
  11.         cmd.Parameters.Add("@DefAmt", SqlDbType.VarChar)
  12.         cmd.Parameters.Add("@Freq", SqlDbType.VarChar)
  13.         cmd.Parameters.Add("@FundID", SqlDbType.Int)
  14.         cmd.Parameters.Add("@FundPct", SqlDbType.VarChar)
  15.         cmd.Parameters.AddWithValue("@Today", Date.Now())
  16.         cmd.Parameters.AddWithValue("@BegDT", "19000101")
  17.         cmd.Parameters.AddWithValue("@EndDT", "24000101")
  18.  
  19.         conn.Open()
  20.         cmd.Connection = conn
  21.         cmd.ExecuteNonQuery()
  22.  
I put the cmd.ExecuteNonQuery() in a Try Catch block to throw a meaningful exception, however that might be out of the scope for your sole inquiry.

Hope this helps.

6 2183
Rabbit
12,516 Expert Mod 8TB
Please post your code using code tags. As a general rule, I do not download attachments.
Apr 2 '14 #2
Robin25
22
Expand|Select|Wrap|Line Numbers
  1.  conn = GetConnect()
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.             MySqlCommand = New SqlCommand("Update Tbl_Member_Profile set F_Name='" & txt_F_Name.Text & 
  9.  
  10. "', M_Name='" & txt_M_Name.Text & "', L_Name='" & txt_L_Name.Text & "', Credit_Line='" & txt_cre_line.Text 
  11.  
  12. & "', Rec_Last_Update='" & Date.Today & "', Age='" & txt_age.Text & "', Date_Of_Birth='" & datepicker.Value 
  13.  
  14. & "', Credit_Rating='" & txt_ranking.Text & "', Membership_Category='" & txt_membership.Text & "' WHERE 
  15.  
  16. P_Member_Code='" & txt_Cus_No.Text & "'", conn)
  17.  
  18.  
  19.             conn.Open()
  20.  
  21.  
  22.  
  23.  
  24.  
  25.             MySqlCommand.ExecuteNonQuery()
  26.  
  27.  
''like this one sir? im sorry this is my first time to join this kind of forum
Apr 3 '14 #3
Rabbit
12,516 Expert Mod 8TB
That error means that one of the values you are inserting is too long for the field.
Apr 3 '14 #4
mcupito
294 256MB
You really haven't given us much to go on. You should really add Parameters when dealing with a database.

See my code for an example:

Expand|Select|Wrap|Line Numbers
  1.         Dim conn As New SqlConnection("Data Source=SQLTEST_HR,4000\SQLEXPRESS;Integrated Security=True")
  2.         Dim cmd As New SqlCommand
  3.  
  4.         'insert statement
  5.         cmd.CommandText &= " INSERT INTO ELECT_SALARY_DFRL (ELECT_XREF_SEQ_ID, EMPL_SALARY_DFRL_AMT, EMPL_SALARY_DFRL_FREQ_CD, "
  6.         cmd.CommandText &= "  FUND_SEQ_ID, ELECT_SALARY_DFRL_FUND_PCT_RT, ELECT_SALARY_DFRL_ELECT_DT, BEG_DT, END_DT)"
  7.         cmd.CommandText &= " VALUES (@SeqID, @DefAmt, @Freq, @FundID, @FundPct, @Today, @BegDT, @EndDT); "
  8.  
  9.         ' parameters for sql insert, from DGV
  10.         cmd.Parameters.AddWithValue("@SeqID", empseqId)
  11.         cmd.Parameters.Add("@DefAmt", SqlDbType.VarChar)
  12.         cmd.Parameters.Add("@Freq", SqlDbType.VarChar)
  13.         cmd.Parameters.Add("@FundID", SqlDbType.Int)
  14.         cmd.Parameters.Add("@FundPct", SqlDbType.VarChar)
  15.         cmd.Parameters.AddWithValue("@Today", Date.Now())
  16.         cmd.Parameters.AddWithValue("@BegDT", "19000101")
  17.         cmd.Parameters.AddWithValue("@EndDT", "24000101")
  18.  
  19.         conn.Open()
  20.         cmd.Connection = conn
  21.         cmd.ExecuteNonQuery()
  22.  
I put the cmd.ExecuteNonQuery() in a Try Catch block to throw a meaningful exception, however that might be out of the scope for your sole inquiry.

Hope this helps.
Apr 3 '14 #5
Robin25
22
Thank you so much Mr.mcupito, it's really works. .
also Mr.Rabbit . .
Apr 4 '14 #6
mcupito
294 256MB
No problem. Hope it helps
Apr 4 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
1
by: Agnes | last post by:
my form got over 30 textbox, as I addnew() and update the record, it said "string & binary data unable trunctated" and that record didn't save in database I used Try catch to check the error, It...
6
by: as400tips | last post by:
I have a Binary Data file (Packed Decimal and ASCII mixed) and would like to convert into ASCII (readable) file. How to do it in C#? Thanks.
6
by: dtarczynski | last post by:
Hello. I have problem when i inserting strings with special characters into MS SQL 2005 database for example:...
7
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"...
1
by: dreamer247 | last post by:
hii My insert quary is giving an error "Server: Msg 8152, Level 16, State 9, Line 1 String or binary data would be truncated. The statement has been terminated. " What may be the...
2
by: sunkesula | last post by:
I update a field in the database that gives the last update time. The first time I edit the item it puts a value in this field. The second time the applications fails with The statement has...
2
by: Elijicity | last post by:
Please I am not an expert but i need detailed reports on how to solve this problem String or binary data would be truncated. The statement has been terminated. I am trying to register online and it...
1
by: kefelegn | last post by:
i am using sql 2005 and asp.net and code behind C# when i try to insert data to table it says "String or binary data would be truncated. The statement has been terminated." any one help me pls be...
2
by: ramuksasi | last post by:
String or binary data would be truncated. The statement has been terminated. I'm using the following code but some times(not all the time) i get the above error can u help Dim ST As String =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.