473,396 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to read csv file containing many special characters?

here is the csv file::::::

Expand|Select|Wrap|Line Numbers
  1. PTNAME,REGNO/ID,BLOOD GRP,WARD NAME,DOC NAME,XRAY,PATHO,MEDICATION,BLOOD GIVEN
  2. 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
in this file from PTNAME to BLOOD GIVEN is headers and file is in proper format. i want to read this file and save in sql server database table. my simple import method doesnt work for this file i need to add some lines in my code bt im confused how to do that .

here is my simple import method if anyone can just edit my method and write code to read and save data in table.

Expand|Select|Wrap|Line Numbers
  1. public void ImportAllFilesOfFolder()//function declares methods to import//
  2. {
  3. try
  4. {
  5. SqlConnection=new SqlConnection(Properties.Settings.Default.HospitalProjectConnectionString);
  6. con.Open();
  7. string sourceDir = txtsend.Text;
  8. var IcsvFile = Directory.EnumerateFiles(sourceDir, "*.csv");
  9.  
  10. foreach (string currentFile in IcsvFile)
  11. {
  12. StreamReader sr = new StreamReader(currentFile);
  13. string line = sr.ReadLine();
  14. string[] value = line.Split(',');
  15. DataTable dt = new DataTable();
  16. DataRow row;
  17.  
  18. foreach (string dc in value)
  19. {
  20. dt.Columns.Add(new DataColumn(dc));
  21. }
  22.  
  23. while (!sr.EndOfStream)
  24. {
  25. value = sr.ReadLine().Split(',');
  26. if (value.Length == dt.Columns.Count)
  27. {
  28. row = dt.NewRow();
  29. row.ItemArray = value;
  30. dt.Rows.Add(row);
  31. }
  32. }
  33.  
  34. SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock);
  35. bc.DestinationTableName = "New";
  36. bc.BatchSize = dt.Rows.Count;
  37. bc.WriteToServer(dt);
  38. bc.Close();
  39. }
  40. }
  41.  
  42. catch
  43. {
  44.  
  45. }
  46. finally { con.Close(); }
  47. }
Apr 21 '15 #1
0 1312

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Roy W. Andersen | last post by:
I've been searching google about this for days but can't find anything, so I'm hoping someone here can help me out. I'm trying to create zip-files without needing the zip-file extension in PHP,...
2
by: nextman | last post by:
A guy called Yuri brought this up a while ago but no one got back to him and now I have the same problem. I have an xml file which contains special characters such as é etc. The DTD...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
25
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found...
8
by: DierkErdmann | last post by:
Hi ! I know that this topic has been discussed in the past, but I could not find a working solution for my problem: sorting (lists of) strings containing special characters like "ä", "ü",......
0
by: themillenium | last post by:
Hello! I am trying to get an html page of urls containing special characters as %21,... "%21" stands for "!",.. e.g.: http://en.wikipedia.org/wiki/Joan_R%C3%B6ell (this page was picked my random)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.