-1

I have a DataTable that I make a DataView with. In the Dataview, I filter and sort the info from the first DataTable. Then I tried to make a new DataTable out of the DataView where I sorted and filtered the content.

Everything seems to work alright but the new DataTable is null, so I lost the content from the original DataTable and the rest of the function does not work anymore. Also, I am getting an Unreachable Code warning in File B @ System.Data.DataTable dt480 = dv.ToTable();

I'll keep trying to solve this but I'd like to see if I am way off, or on the right track. Thanks in advance.

I have two files where the code is stored.

File A:

static public void ElecOneLine1(System.Data.DataView dv)
    {
        string Path = Commands.LoadFile();
        System.Data.DataTable table = Commands.ReadExcelToTable(Path);
        Commands.ElecDv480V(table);            
        //Commands.OneLineDt(dv);                                  
        Commands.InsertElec1LineBlockscd();
        Commands.DrawOneLineBuscd("OneLineBackground", 35.5478, 23.3750, 0, table.Rows[0]);            
        for (int i = 1; i < 8; i++)
        {
            Commands.DrawOneLineItem("" + table.Rows[1 + i][0], 4 + ((double)i * 3), 12.6835, 0, table.Rows[0], i + 1);                
        }
    }

File B (called "Commands"):

public static DataView ElecDv480V(System.Data.DataTable dt)
    {
            System.Data.DataView dv = new DataView(dt);
            dv.RowFilter = "F1 = '480V'";
            dv.Sort = "F2 ASC, F3 ASC";
            return dv;               
            System.Data.DataTable dt480 = dv.ToTable();                                      

    }
nebsi04
  • 41
  • 3
  • 8
  • Well, I figured the problem out, but I had to move the code on File B to File A. I was trying to find out how to keep everything isolated. – nebsi04 Oct 05 '16 at 05:48

1 Answers1

2

return should be the last statement.The return statement terminates execution of the method in which it appears

public static DataView ElecDv480V(System.Data.DataTable dt)
    {
            System.Data.DataView dv = new DataView(dt);
            dv.RowFilter = "F1 = '480V'";
            dv.Sort = "F2 ASC, F3 ASC";                           
            System.Data.DataTable dt480 = dv.ToTable();   
            return dv;                                

    }

Also,You are returning a dataview so you need to have a variable at receiving end also which you are missing.Beside what is the use of setting values for dt480

Vicky
  • 2,027
  • 1
  • 19
  • 31