Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can anyone help me on how to add data(email address) from excel sheet and notepad to a table in mssql using asp.net. Each user can have more than one email address. I checked certain codes but not satisfactory. give me an explanation on how the code will identify each column header in case of excel and email addresses in case of notepad. Any codes.
Posted
Comments
Sergey Alexandrovich Kryukov 17-May-13 2:25am    
Notepad? How's that? :-)
—SA
Nibu Kurian 17-May-13 2:43am    
Maybe just give the email id and take it from there.. orelse leave that just tell me how to get it from excel sheet.. the code shud have provision to insert more than one mail id for single user.
Sergey Alexandrovich Kryukov 17-May-13 3:00am    
Notepad, no kidding? (Notepad is Microsoft application, totally stand-along, not communication with any other in any way... in case you don't know what is it.)
—SA
Nibu Kurian 17-May-13 3:07am    
Well leave notepad.. just tell me how to read data(single column with many email ids) from excel sheet ..and then insert it to table..
StM0n 17-May-13 3:06am    
Did you mean data from a textfile? Otherwise getting data from notepad could be interesting...

1 solution

Use regex to parse the text.

C#
using System.Text.RegularExpressions;
...
string input="someone@somedomain.com.au is an email address... and someone@anotherdomain.com is yet another one.";
string pattern="\\b[\\w\\.-]+@[\\w\\.-]+\\.\\w{2,4}\\b";
var matches =Regex.Matches( input,pattern);
string[] addresses = matches.OfType<match>().Select(m => m.Value).ToArray();


your input string would be the contents of your text file or in the case of excel you could read each cell into a StringBuilder variable.

ATG
 
Share this answer
 
v2

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