I am reading data from a csv file using Oledb in C#
I also want to retrieve row number with the records of the file
I know this can be done in Ole db using the command
SELECT rank = ( SELECT COUNT(*) FROM tableName b WHERE a.ID > b.ID ), * FROM tableName a ORDER BY a.ID
this can be done in SQl Server using:
SELECT ROW_NUMBER() OVER (ORDER BY ID) AS Row FROM TableName
But I want to read data from a csv file and there I want to add a column as RowNumber using any of the above query
But it is throwing me following exception
"No Value given for one or more parameters"
My whole code is as follows:
void ReadData(string FilePath)
{
string connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text;", System.IO.Path.GetDirectoryName(FilePath));
string CommandString = "SELECT rank = ( SELECT COUNT(*) FROM {0} b WHERE a.ID > b.ID ), * FROM {0} a ORDER BY a.ID";
CommandString = string.Format(CommandString ,Path.GetFileNameName(FilePath) );
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(CommandString , connString);
DataTable dataSet = new DataTable();
dataAdapter.Fill(dataSet);
dgv.DataSource = dataSet;
}
Can any one provide any help, what I should do to Add one more column as RowNumber while reading data from a csv file