Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
>String or binary data would be truncated
VB
Dim bError As Boolean = False
       Dim tdate As New Date
       tdate = System.DateTime.Now()

       Dim myConnection As New SqlConnection(Utility.CurrentConnectionString)
       myConnection.Open()
       Try
           If Page.IsValid Then
               Dim myCommand As SqlCommand = New SqlCommand
               Dim mycommand1 As SqlCommand = New SqlCommand
               myCommand.Connection = myConnection
               myCommand.CommandText = update command................;
               '  myCommand.ExecuteNonQuery()

               myCommand1.Connection = myConnection

               myCommand1.CommandText = insert command................;

               myCommand.ExecuteNonQuery()
            mycommand1.ExecuteNonQuery()

                 submitbtn.Enabled = False
           End If
Posted
Updated 5-May-12 0:25am
v5

Compare your columns char or nvarchar length and your value length
 
Share this answer
 
Comments
mani.kishore.asp.net 5-May-12 8:09am    
all are varchar
Dain Ucak 5-May-12 8:14am    
i mean check your columns capacity and check your values which you want to send to sql
you need to use myCommand.Parameters.Clear method before using another ExecuteNonQuery functiojn
 
Share this answer
 
Comments
mani.kishore.asp.net 5-May-12 6:24am    
still same error





Dim myConnection As New SqlConnection(Utility.CurrentConnectionString)
myConnection.Open()
Try
If Page.IsValid Then
Dim myCommand As SqlCommand = New SqlCommand
Dim mycommand1 As SqlCommand = New SqlCommand
myCommand.Connection = myConnection
myCommand.CommandText = update command................;
myCommand.ExecuteNonQuery()
myCommand.Parameters.Clear()
myCommand1.Connection = myConnection

myCommand1.CommandText = insert command................;


mycommand1.ExecuteNonQuery()

submitbtn.Enabled = False
End If
There is no need to create two command objects you can make a function and pass two querys one by one which solve your problem.
 
Share this answer
 
most of the times, this problem occuers when the length of the value (data) is greater than the length of Column in which you are putting (Inserting/Updating) values.

Just check the length of the column and also make sure you are putting the right data in columns (i.e. check Data Type of column).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900