Trigger prevents deletion from SQL Server Table

Hi,

I use the code below to delete records from a table called Distribution. The deletion works fine each time. But I need to have an after delete trigger for that table and each time I create the trigger the delete code gives the error:
String or binary data would be truncated.
The statement has been terminated.

Here is the code for the Trigger:
ALTER Trigger [dbo].[DelTicket] on [dbo].[Distribution]
After Delete As
Begin
if ((Select count(*) from Deleted) > 1)
Rollback Tran
else
Insert Into dbo.ClosedTickets
Select * From
Deleted
End

And here is the code for the delete statement:

 public void deleteTicket(int selectedID)
        {
             SqlConnection con = null;
            con = new SqlConnection("Server=PC;;Database=SupportProject;integrated security=True");
            SqlCommand comm = new SqlCommand("delete from Distribution where ID=@ID",con);
                 comm.Parameters.AddWithValue("@ID", System.Data.SqlDbType.Int);
            comm.Parameters["@ID"].Value = selectedID;
            con.Open();
            // Execute the command
            comm.ExecuteNonQuery();
            con.Close();
        }
adamtraskAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Habib PourfardSoftware DeveloperCommented:
probably some column data types in ClosedTickets doesn't match Distribution table. make sure the length of varchar columns are the same.

but I don't know why did you wrote this statement: if ((Select count(*) from Deleted) > 1) Rollback Tran
because it's an after delete trigger and for sure some records have been deleted and I also can't see any defined transactions to be rolled back.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adamtraskAuthor Commented:
You are  so right "not to understand why", I don't understand why I didn't see any of that.

A whole column was missing and I spent most of the day trying to look for errors in the code...

I guess experience makes perfect, and I don't have much of that. So I learn the hard way.

Thank you so much for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.