Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi developers,

I have a csv file that is loaded in datagridview by using dataset.
The problem is:

I want to change dates format in dataset not in datagridview before loading a csv file in datagridview

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 cmdstring = string.Format(@"SELECT *FROM {0}", Path.GetFileName(filename));
           string cmdstring1 = string.Format(@" select convert(varchar, getdate(), 103  From {0}") ,(YourFieldPath.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.SelectCommand = new OleDbCommand(cmdstring1, olconn);
                adapter.Fill(dataset, "Test");
                olconn.Close();               
            }
          return dataset;
        }


but when I write a code like this

select convert(varchar, getdate(), 103 From{0})


an error is raised: "Invalid argument"

A main problem is that dateformat change in multiple columns
not single or more dates are split into multiple rows and columns
so I do not know how more columns are changed.

I want to change all of the columns rows dates in dataset, by using this sql query.
Posted
Updated 17-Nov-10 19:28pm
v2

1 solution

Hi Vishu,

You are missing right parentheses in following variable:
string cmdstring1

Please use following line instead of your.
C#
string cmdstring1 = string.Format(@" select convert(varchar, getdate(), 103)  From {0}" ,YourFieldPath.GetFileName(filename)); 

Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer":rose: if this would be correct answer.
Thanks,
Imdadhusen
 
Share this answer
 
v2
Comments
Dalek Dave 18-Nov-10 4:30am    
Good Call.

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