Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I want to get the column name which getting error. I am using try catch but it gives me only few information. How I get this information?

Thanks in advance.

Posted
Comments
manavya 20-Oct-11 3:20am    
what is error ? explain more about it.
angle57 20-Oct-11 3:40am    
error is like convertion and casting. i have the error number and Procedure name. but want the column name also.
sachin10d 20-Oct-11 3:48am    
give the error details
angle57 20-Oct-11 3:52am    
As i have 25 columns and out of this some columns have INT data type but when i insert data from the XLS file it may take VARCHAR value also. so it cause error for the convertion.
now i want the name of that column which have error.

1 solution

Normally, when you cause an SQL exception is is pretty explicit: it either gives you a name:
System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'description'

or at a minimum a column reference number.
Look at the exception: if you use Exception.Message you will get a bare-bones version. If you look at Exception.ToString() you will get a more detailed (and mostly stack trace) explanation. Put a breakpoint on the first line of the catch block - you may be able to work it out from there.
 
Share this answer
 
Comments
angle57 20-Oct-11 3:39am    
Sorry to tell you that i must code in SQL Server 2005 i cant use C# or else.
please sugest me the SQL Server code.

Thanks, again.
OriginalGriff 20-Oct-11 4:01am    
The error message is the same: when SQL server encounters an error it feeds the error code and text up to the .NET framework. So if you look at teh message in the SQL server management studio (or whatever you are using) then the text should identify the error, if only by a row and column index in the original text.
angle57 20-Oct-11 6:03am    
As i have 25 columns and out of this some columns have INT data type but when i insert data from the XLS file it may take VARCHAR value also. so it cause error for the convertion.
now i want the name of that column which have error.

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