Click here to Skip to main content
15,914,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to store string value into data table, pick from for each loop i am doing like that

C#
char[] delimiterChars = { ' ', ',', '.', ':', '\t' };

        string Text = exDT.Rows[i]["Sender Name"].ToString();
        string[] words = Text.Split(delimiterChars);

        DataTable dt1 = new DataTable();
        foreach (string s in words)
        {
      DataRow row = dt1.Rows[s] //<- in this line  error occurs;
        }
Posted
Updated 29-Oct-15 0:47am
v2
Comments
Maciej Los 29-Oct-15 6:47am    
What kind of error?
Noman Suleman 29-Oct-15 7:23am    
issue resolved

You need to create a new row each time - and some columns would help as well!
Try this:
C#
char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
string Text = exDT.Rows[i]["Sender Name"].ToString();
string[] words = Text.Split(delimiterChars);
DataTable dt1 = new DataTable();
dt1.Columns.Add("Word", typeof(string));
foreach (string s in words)
    {
    dt1.Rows.Add(s);
    }
 
Share this answer
 
v2
Comments
Noman Suleman 29-Oct-15 7:02am    
thanks
OriginalGriff 29-Oct-15 7:18am    
You're welcome!
Now you will check.......

char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
string Text = exDT.Rows[i]["Sender Name"].ToString();
string[] words = Text.Split(delimiterChars);
DataTable dt1 = new DataTable();
foreach (string s in words)
{
DataRow dr = dt1.NewRow();
dr["Your DataTable Column Name"]=s.ToString();
dt1.Rows.Add(dr);
}
 
Share this answer
 
Comments
Noman Suleman 29-Oct-15 7:02am    
thanks

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