Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
System.Data.DataTable db = GetExcelData(path, oSheet.Name);
                foreach (DataColumn item in db.Columns)
                {
                    string Value = db.Rows[0]["Year"].ToString();
                    columnNames.Add(item.ColumnName);
                }

i have problem when i use filter row in datatable the column name contain extra value like (_x0020_) how can avoid this problem even the columns contain one word and no space...
when I check the result in the xml its showing the year like <year_x0020_>1427<year_x0020_>

so how can I find this value in the Year column

Best regard
Posted
Updated 8-Jan-13 2:51am
v3
Comments
OriginalGriff 8-Jan-13 5:22am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps the code fragment which sets the filter would help?
Use the "Improve question" widget to edit your question and provide better information.
Satyendra Kumar(Analyst Programmer) 8-Jan-13 5:33am    
Hi please share the little code so that we can understand your code and requirements. May be you can solve it by using type conversion. First convert it to ToString() and then again to your desired type.

1 solution

CSS
dataView.RowFilter = "empid = 8";

Other examples are
dataView.RowFilter = "EmpName = 'Pankaj'" ;
dataView.RowFilter = "Date = #12/08/2000#" ;

Comparision
dataView.RowFilter = "Date>=" + "#" + startdate + "#" +
"And Date <=" + "#" + enddate + "#";
You can find other examples at:
http://www.csharp-examples.net/dataview-rowfilter/
 
Share this answer
 
Comments
Member 8194711 9-Jan-13 0:39am    
i tried all the examples not working fine.
when i want to discover what is the error i found <year><year> tag its come like this <year_x0020_><year_x0020_> so how can i found the Year column in this <year_x0020_><year_x0020_>
Member 8194711 9-Jan-13 0:54am    
the main problem i cannot find the column because is has some extra signals i dont know how its came and how can i find the column with this extra signal
<year><year> <year_x0020_><year_x0020_>
Jibesh 9-Jan-13 2:22am    
was the DataTable Columns AutoGenerated ? please post the sample code of how you prepare the DataColumn inside the GetExcelData method
Member 8194711 9-Jan-13 2:26am    
protected System.Data.DataTable GetExcelData(string ExcelFilePath, string sheetName)
{

string OledbConnectionString = string.Empty;
OleDbConnection objConn = null;
OledbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFilePath + ";Extended Properties=Excel 8.0;";
objConn = new OleDbConnection(OledbConnectionString);

if (objConn.State == ConnectionState.Closed)
{
objConn.Open();
}

OleDbCommand objCmdSelect = new OleDbCommand("Select * from [" + sheetName + "$]", objConn);
OleDbDataAdapter objAdapter = new OleDbDataAdapter();
objAdapter.SelectCommand = objCmdSelect;
DataSet objDataset = new DataSet();
objAdapter.Fill(objDataset, "ExcelDataTable");
objConn.Close();
return objDataset.Tables[0];
}
askkk 11-Apr-13 6:10am    
why?

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