Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Developers,
I am Vishal Sharma
I load a csv file into datagridview using dataset.
I sort a three each columns and rows by headertext

my code is:
public static DataSet GetDataset(string filename)
{
  string Connectionstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text;",
            Path.GetDirectoryName(filename));
  string cmdstring1 = string.Format(@"select * FROM {0} order by ID_NUM desc,START_DATE asc,END_DATE asc", Path.GetFileName(filename));
            DataSet dataset = new DataSet();
          
  using (OleDbConnection olconn = new OleDbConnection(Connectionstring))
  {
    olconn.Open();
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    adapter.SelectCommand = new OleDbCommand(cmdstring, olconn);
    adapter.Fill(dataset, "Test");
    olconn.Close();               
  }
  return dataset;
}

public void Loaded_Click(object sender, EventArgs e)
{          
  DataSet dataset = Form1.GetDataset(Locations.Text);
  DGV.DataSource = dataset.Tables[0].DefaultView;
}


The problem is that if START_DATE is write like this start date
and if END_DATE is write like this end date
exception does occur
invalid string
and file cannot be loaded.
So, tell me which condition is applied in the code if alphabet of start date and the end date are return in any order they are match at load time of csv file.
Please accept my request and solve this situation. Thank you.
Posted
Updated 13-Nov-10 2:07am
v2
Comments
Henry Minute 13-Nov-10 10:46am    
If you are having trouble sorting and require help, it would make it easier if you showed the code that does the sorting, or the expression that you use if you are doing it with some property.

1 solution

put it in brackets

i.e. end date would have to be [end date] or 'end date'

I would also suggest doing the sorting IN code, so your using the table Default View and then you can give some more custom sorting options if needed. Remove the sort at the end of your statement and do this:

C#
DataTable objtb = new DataTable();
// Do stuff to fill objtb here
DataView dv = objtb.DefaultView;
dv.Sort = "[start date] asc, [end date] asc";
DGV.DataSource = dv;
 
Share this answer
 

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