Link to home
Get AccessLog in
Avatar of Mohammad Aamir Qureshi
Mohammad Aamir QureshiFlag for Australia

asked on

Read From File and Insert into Table

AOA
Well i have a text file with 100 records(100 Line)
"Name","NIC","Number", (This record is present in Text File)
how can i read it and it is separated by Qomma (,)
When i read it , it is enter in Table also like
Name: Aamir
NIC:    1313113
Number:123123
and also tell me how can i generate the XML
Thankx


Avatar of dash420
dash420
Flag of Canada image

this way you can read the text file

 StreamReader re = File.OpenText(@"c:\Test.txt");
 string input = null;
 while ((input = re.ReadLine()) != null)
 {
        string[] arr = input.Split(',');
         string name = arr[0];
         string nic = arr[1];
         string number = arr[2];
         // Here you can write your insert statement as the values of one line is fetch and set to local variable  
  }
            re.Close();

About your second comment i am not clear what you are looking for.
Avatar of Mohammad Aamir Qureshi

ASKER

Thanks
Welll my second question is that how can i generate the XML on the basis of each Line
Thankx

ASKER CERTIFIED SOLUTION
Avatar of dash420
dash420
Flag of Canada image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Thank you very much
i want to know one more information from u
This is my line
"Aamir","12313","11111",
How can i remove the double quotation because after reading from file i enter record in database
Once Again Thankx

use this
string name = arr[0].Replace("\"", "").Replace("\"", "");
string nic = arr[1].Replace("\"", "").Replace("\"", "");
tring number = arr[2].Replace("\"", "").Replace("\"", "");
Thank youu
very much

once again thanks

You are highly appreciated

Take care
Thank you.
Regards,
Dash