Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
OleDbConnection co = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;;Data Source=" + txtpathname.Text + " ;Extended Properties=Excel 8.0;
co.Open();
OleDbDataAdapter da = new OleDbDataAdapter("select MobileNo,Degree from [FristSheet$] where Degree=(select max(Degree) from [FristSheet$] where Name ='Arun')", co);


Find the line no or column no display in message box.
When i misspell the column name like -> 'MobileNo' i give as MbileNo as in initialize that time error occurred on that time i want to display the certain Line no and Column no
Posted
Updated 4-Oct-15 19:59pm
v8
Comments
[no name] 4-Oct-15 9:36am    
As per your code, you should error line no. What is the value you are getting in line variable in your code?
Hari prakash R 4-Oct-15 9:47am    
i want to get column number of error where occured i get 0(zero) value only i can't get the original column no
[no name] 4-Oct-15 11:09am    
Try below code:

int linenum = Convert.ToInt32(ex.StackTrace.Substring(ex.StackTrace.LastIndexOf(":line") + 5));
Hari prakash R 4-Oct-15 11:47am    
thanks it's work fine but it's perfectly work for get the line no but i want to get the column no also that is my problem....
[no name] 4-Oct-15 12:10pm    
Did you try with below code:

//Get a StackTrace object for the exception
StackTrace st = new StackTrace(ex, true);

//Get the first stack frame
StackFrame frame = st.GetFrame(0);

//Get the column number
int col = frame.GetFileColumnNumber();

1 solution

Depends where the error occurred: If you look at the documentation[^] it says:
Return Value
Type: System.Int32
The file line number, or 0 (zero) if the file line number cannot be determined.
So if the location of the error has no file information, you will get zero.
The GetFileColumnNumber returns zero under the same conditions.

Try it by deliberately throwing an error in your own code and see what happens.
 
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