Thursday, September 19, 2013

Performing query on a table, return value is null

Hi Ahmed-samy. I am suspecting that here is something wrong with my regex method resulting in nothing was written into the table.



string captureformat = @"\#(?'firstName'\w+)&(?'lastName'\w+)&(?'dateOfBirth'\w+)&(?'email'\w+)&(?'streetAddress'\w+)&(?'suburb'\w+)&(?'state'\w+)&(?'postcode'\w+)&(?'positionNumber'\d+)\s*";
//matching captured format
Regex expr = new Regex(captureformat);
MatchCollection matches = expr.Matches(input);
foreach (Match match in matches)
{//storing captured format into table
DataRow newRow = table.Rows.Add();
newRow["firstName"] = match.Groups["firstName"].Value;
newRow["lastName"] = match.Groups["lastName"].Value;
newRow["dateOfBirth"] = DateTime.Parse(match.Groups["dateOfBirth"].Value);
newRow["email"] = match.Groups["email"].Value;
newRow["streetAddress"] = match.Groups["streetAddress"].Value;
newRow["suburb"] = match.Groups["suburb"].Value;
newRow["state"] = match.Groups["state"].Value;
newRow["postcode"] = match.Groups["postcode"].Value;
newRow["positionNumber"] = int.Parse(match.Groups["positionNumber"].Value);
}


No comments:

Post a Comment