Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
thusi
Starting Member
25 Posts |
Posted - 2008-10-24 : 08:09:51
|
Hi AllI have a SP which has input and output parameters and also some user-defined datatypes (of type varchar). It works fine when I run it directly in Management Studio, and I get 2 datatables and 2 ints as output of this sp.However, when I try running it from C#, I keep getting a "String or binary data would be truncated.The statement has been terminated" exception. I basically have:SqlCommand command = new SqlCommand("sp_name", conn);command.CommandType = CommandType.StoredProcedure;command.Parameters.Add("@xx", SqlDbType.type).Value = xx;...rest of the in paramscommand.Parameters.Add("@xx", SqlDbType.Int).Direction = ParameterDirection.Output;SqlDataAdapter adapter = new SqlDataAdapter(command);DataSet dataSet = new DataSet();adapter.Fill(dataSet);It's at the very last line - ie. the Fill line that I keep getting the annoying sql error :( Any ideas?Thanks |
|
thusi
Starting Member
25 Posts |
Posted - 2008-10-24 : 18:28:21
|
Ok..after spending some frustrating amount of time I found out this was cos I had a varchar(50) somewhere and was passing more chars than that :( I've seen this error in other forums too with all sorts of explanations..but guess this could be one of the 1st things to look out for! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-25 : 02:41:43
|
quote: Originally posted by thusi Ok..after spending some frustrating amount of time I found out this was cos I had a varchar(50) somewhere and was passing more chars than that :( I've seen this error in other forums too with all sorts of explanations..but guess this could be one of the 1st things to look out for!
one general guideline to prevent this is always make sure lengths given for all fields in procedure in all temp tables and even variables should be according to length of actual source fields from which it gets the data. |
|
|
|
|
|