Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
How to use DataView RowFilter Syntax [C#]with space tag Ex: i want to filter using RowFilter Year="1427" but its showing me error (Error !Cannot find column Year ).
i discover why this message is showing because Year column has some space...
 
DataView dv = myDs.Tables[0].DefaultView;
dv.RowFilter = "Year=1427";
gv.DataSource = dv;
gv.DataBind();
Posted 9 Jan '13 - 23:27

Comments
Shanu2rick - 10 Jan '13 - 5:31
And Your Problem is...?
pranathis012 - 10 Jan '13 - 5:32
please check in your dataset what are the column names are available
Member 8194711 - 10 Jan '13 - 5:33
I can't Find the Year column its show me Error how can i find column its has space how can i avoid that space
Shanu2rick - 10 Jan '13 - 5:37
Where is this space exactly in your Column 'Year'?
Member 8194711 - 10 Jan '13 - 5:56
Sir i dont know actually so there is any way to avoid the space
pranathis012 - 10 Jan '13 - 5:38
in your dataset there is no column with the name "year" then how can you filter based on year.please be concentrate on dataset first ,and then filter .
Member 8194711 - 10 Jan '13 - 5:40
i have column called year when i convert my dataset to xml my year column its show like this
pranathis012 - 10 Jan '13 - 5:41
show me your code once
Member 8194711 - 10 Jan '13 - 5:50
System.Data.DataTable db = GetExcelData(path, oSheet.Name); 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]; } DataView dv = myDs.Tables[0].DefaultView; foreach (DataColumn item in db.Columns) { string sss = db.Rows[0][item.ToString()].ToString(); columnNames.Add(item.ColumnName); if (item.ColumnName.Trim() == "Year") { dv.RowFilter = "Year=1425"; gv.DataSource = dv; gv.DataBind(); } }
pranathis012 - 10 Jan '13 - 6:03
please put a break point in GetExcelData method and check the data properly in this code your doing you fetch information from excel sheet itself i think the problem is 1) there is no column like year 2) spaces 3) spell ...etc.. once put a break point and check in which line its showing error
Shanu2rick - 10 Jan '13 - 5:42
Yeah, Me too
Member 8194711 - 10 Jan '13 - 5:55
System.Data.DataTable db = GetExcelData(path, oSheet.Name); 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]; } DataView dv = myDs.Tables[0].DefaultView; foreach (DataColumn item in db.Columns) { string sss = db.Rows[0][item.ToString()].ToString(); columnNames.Add(item.ColumnName); if (item.ColumnName.Trim() == "Year") { dv.RowFilter = "Year=1425"; gv.DataSource = dv; gv.DataBind(); } }
Shanu2rick - 10 Jan '13 - 6:10
Your Code looks fine. Review your ExcelSheet, especially the column 'Year'.

1 solution

Hi,
 
please be check in your Dataset having the column name "year" or not.
 
Please be check it once. If the column name is avilable in your dataset then please be check the spell and caps letters also..
  Permalink  
Comments
Member 8194711 - 10 Jan '13 - 5:42
yah i have column it called year but it has some space when i convert dataset to xml the year column its show like this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 223
1 Ron Beyer 220
2 Aarti Meswania 200
3 Mahesh Bailwal 175
4 Rohan Leuva 170
0 Sergey Alexandrovich Kryukov 8,553
1 OriginalGriff 6,899
2 CPallini 3,648
3 Rohan Leuva 2,963
4 Maciej Los 2,308


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid