Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
string dsource = @"C:\Users\Comma\Desktop\Working ON\WebBasedData\WebBasedData\Data\Attachments_20131219";

//Put your datasource path in the connection string for example if you have csv files in D:\ directory change datasource= D:\
string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dsource + ";Extended Properties='text;HDR=Yes;FMT=Delimited';";

            try
            {
                txtFromDate1.Text = Convert.ToString("MMDDYY");
                txtToDate1.Text = Convert.ToString("MMDDYY");
                string fromdate = txtFromDate1.Text;
                string todate = txtToDate1.Text;
                string fromtime = DropDownList2.SelectedItem.Text;
                string totime = DropDownList3.SelectedItem.Text;


                con.ConnectionString = constr;

                //create instance for command object 
                OleDbCommand cmd = new OleDbCommand();
               

                cmd.Connection = con;   
                // set your file name in the below query
                cmd.CommandText = "select * from [fpyield && fromdate && fromtime ]" ;
                
  
                //Open Oledb Connection to read CSV file 
                con.Open();

                //Create one datatable to store data from CSV file
                DataTable dt = new DataTable();

                // Load Data into the datatable 
                dt.Load(cmd.ExecuteReader());
           
                //Bind data in the Gridview
                GridViewShow.DataSource = dt;
                GridViewShow.DataBind();

HI is it possible for me not to read my CSV file in this way "select from [fpyield 12162013 0930] but i want to "select [fpyield differentdate differenttime]" the differentdate and time is selected from a dropdownlist..... thank you
Posted
Updated 28-Dec-13 4:36am
v3

This is a real mess. Your ASP.NET website cannot see inside your whole file system, only under the web root. Is that path inside your web site ?

Convert.ToString("MMDDYY");

returns "MMDDYY". This is non code, a waste of time. Why are you using it ?

string fromdate = txtFromDate1.Text;

This is, by definition, not a date, but "MMDDYY".

cmd.CommandText = "select * from [fpyield && fromdate && fromtime ]" ;

This is not selecting the value of fromdate or fromtime. It's selecting the constant values "fromdate" and "fromtime". Is this what you meant ?

select from [fpyield 12162013 0930]

This is not what you are doing, not even remotely. I suggest you learn how to use your debugger, so you can see what your code is doing, and how it differs from what you expect.
 
Share this answer
 
Comments
acing wei 28-Dec-13 1:19am    
oops i should take the mmddyy out ...is my mistake... wht i mean is if i use the "select from [fpyield 12162013 0930.csv]" it will read n show me the table in the csv file...instead of doing that what i want is "select from [fpyield fromdate fromtime.csv]" fromdate where i can select different date and fromtime i can select different time. because i got a lot of csv file with different date and time. im doing my final year project and i really need help. thank you ...
Christian Graus 28-Dec-13 1:22am    
This is a really ugly way to do things in 2013. Why are you using csvs at all ? Anyhow, as far as I can tell, the support is only for selecting entire columns. Once you have a data set, you can search it in your code. Or you can use SSRS or a stored proc to insert the values in to a real database, and search them there.

acing wei 28-Dec-13 1:38am    
i actually suggest my teacher to use database but he refused to... and he forced me to use csv file to read... and i stuck ..i have no idea how to continue but he keep saying this is an easy programme... anyway thank you....
Christian Graus 28-Dec-13 1:39am    
Your teacher is a moron. This should worry you. You can use a CSV, but you need to process it in code. I repeat, your teacher is a moron.
acing wei 28-Dec-13 1:44am    
Do you have any small sample regarding csv .... if not then never mind...i appreciate it, thank you
 
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