Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 10-Jan-13 0:27am
Comments
Shanu2rick at 10-Jan-13 5:31am
   
And Your Problem is...?
Member 8194711 at 10-Jan-13 5:33am
   
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 at 10-Jan-13 5:37am
   
Where is this space exactly in your Column 'Year'?
Member 8194711 at 10-Jan-13 5:56am
   
Sir i dont know actually so there is any way to avoid the space
Member 8194711 at 10-Jan-13 5:40am
   
i have column called year when i convert my dataset to xml my year column its show like this
Member 8194711 at 10-Jan-13 5:50am
   
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 at 10-Jan-13 5:42am
   
Yeah, Me too
Member 8194711 at 10-Jan-13 5:55am
   
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 at 10-Jan-13 6:10am
   
Your Code looks fine.
Review your ExcelSheet, especially the column 'Year'.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v2
Comments
Member 8194711 at 10-Jan-13 5:42am
   
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
0 DamithSL 315
1 Zoltán Zörgő 170
2 OriginalGriff 150
3 Sergey Alexandrovich Kryukov 120
4 Maciej Los 115
0 OriginalGriff 7,760
1 DamithSL 5,874
2 Sergey Alexandrovich Kryukov 5,444
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100