I am new in C#..struggling to learn it..Can anyone help me in this..i want to know how can i go from one row to other row based on previous row value..
Example:1st row-> MerchantNo:001102534
2nd row->OutletName
3rd row->Emptyrow
4th row ->MerchantNo TerminalNum CardType ....
5th row ->1102534 7700100456 Amex
I am having a datatable filled with this kind of data..I have written a code for removing the characters from 1st row and to give only the number.Now based on this number i want to go to all those rows which contains this number and want to retrieve the data from that row and insert it into sql table..
how can i do this...hope u understood my doubt..This is the code which i have written..
string Mno = "";
foreach (DataRow rowExcel in dtExcel.Rows)
{
foreach (DataColumn colExcel in dtExcel.Columns)
{
Mno = rowExcel[colExcel].ToString().Trim();
if (Mno != "")
{
string Mno1 = Mno.Substring(16, 10);
Mno =Mno1.ToString();
//Int32 MerchNo = Convert.ToInt32(Mno);
}
break;
}
if(Mno!="")
break;
}
How can i proceed further..
Loading

Posted Sep 5, 2011, 1:23 AM EDT
EnumerableRowCollection query = from row in dtExcel.AsEnumerable() where row.Field("Mno").Contains("number") select row; DataView view = query.AsDataView(); The filtered records will be in the query dataview and you can process this dataview to insert the records into SQL. http://msdn.microsoft.com/en-us/library/bb669073.aspxPlease try this. I haven't tested this one.
nazima3 reputationPosted Sep 5, 2011, 2:13 AM EDT
Jackuline Savarimuthu4 reputationPosted Sep 19, 2011, 2:55 AM EDT
You can loop through each row of data table and can check the value as below:
foreach (DataRow dr in dataTable.Rows)
{
if(dr["ColumnName"].ToString() == "B")
{
//Your code goes here.
}
}