Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
2.22/5 (2 votes)
See more:
here is the file which i want to read but no output comes why it is not getting any result

here is my code:

C#
public void ImportAllFilesOfFolder()//function declares methods to import//
       {
           try
           {
               //con.Open();
               string sourceDir = txtsend.Text;
               var IcsvFile = Directory.EnumerateFiles(sourceDir, "*.csv");

               foreach (string currentFile in IcsvFile)
               {
                   StreamReader sr = new StreamReader(@"C:\Users\Send\BED01.csv");
                   string line = sr.ReadLine();
                   string[] value = line.Split(',');
                   DataTable dt = new DataTable();
                   DataRow row;

                   foreach (string dc in value)
                   {
                       dt.Columns.Add(new DataColumn(dc));
                   }

                   while (!sr.EndOfStream)
                   {
                       value = sr.ReadLine().Split(',');
                       if (value.Length == dt.Columns.Count)
                       {
                           row = dt.NewRow();
                           row.ItemArray = value;
                           dt.Rows.Add(row);
                       }
                   }
                   con.Open();
                   SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock);
                   bc.DestinationTableName = "PatientView";
                   bc.BatchSize = dt.Rows.Count;
                   bc.WriteToServer(dt);
                   bc.Close();
               }
           }

           catch(System.ArithmeticException e)
           {
               MessageBox.Show(e.Message);
           }
           finally { con.Close(); }
       }

and here is csv file structure:


PTNAME,REGNO/ID,BLOOD GRP,WARD NAME,DOC NAME,XRAY,PATHO,MEDICATION,BLOOD GIVEN
Mr.MISHRA SABHAPRASAD RAMNARESH,SH1312/00804,,SEMI DELUXE 05,SHELKE SAMEER,"X RAY LEFT HIP WITH THIGH AP/LAT --ACCEPTABLE WITH IMPLANT IN SITU WITH ACETABULAR CUP ARTHRITIC CHANGES 2 D ECHO-MILD CONC LVH GOOD LV DIASTOLIC FUNCTION ALTERED LV DIASTOLIC FUNCTION LVEF 55 % MRI BRAIN- FEW OLD ISCHEMIC CHNGES IN BILATERAL CEREBRAL WHITE MATTER MRI L-S SPINE WITH SCREENING OF WHOLE SPINE- PID-L3-4,L5-S1 PID C3- 4TO C6-7 ",HB- 11.4 BSL -206.4 SR CREAT-1.7 T3-0.74 T4-11.0 TSH-1.79 SR UREA-23 BLOOD GROUP- B RH POSITIVE PT INR-15/15/1 HIV AND HBSAG - NEGATIVE, IV DICLOGESIC RR DRIP 1-0-1 TAB TACIL 1-0-1 TAB ARCOPAN D 1-0-1 CAP GEMCAL PLUS 1 -0-1 TAB ANXIT 0.5 MG 0-0-1 ARCIZEN GEL LA 1-1-1-1 ,I POINT PCV GIVEN ON 6/4/2015 B RH POSITIVE
Posted
Updated 16-Apr-15 18:33pm
v2
Comments
Sinisa Hajnal 17-Apr-15 2:38am    
Is this single line? Or the file is broken into multiple lines? What do you get in value? How many rows in the datatable? Does PatientView table corresponds in structure to this file? What is the final result in your datatable?

Add generic Exception at the end and check if you get something unexpected. Set a breakpoint and check values before sending them to the database.
Florian Braun 17-Apr-15 2:47am    
did you check if the DataTable contains the data as you wanted to be? So is it a problem with reading the FIle into this Datatable or is it a problem with SQLcopy?
Member 11543226 17-Apr-15 5:56am    
yes i create data table as per these file headers and this is in proper format

 
Share this answer
 
this code not support me it is quite difficult to understand cn anyone give me simple code link
 
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