Dinesh Santhalingam

Dinesh Santhalingam

  • NA
  • 737
  • 368.5k

Data table to array and return array

Dec 28 2016 1:10 AM
  1. [System.Web.Services.WebMethod]
  2. public void loaddata()  
  3. string sql = "SELECT Name,Time,Inuse FROM table4";  
  4.   using (SqlConnection Connection = new SqlConnection((@"Data Source)))  
  5.            {  
  6.                using (SqlCommand myCommand = new SqlCommand(sql, Connection))  
  7.                {  
  8.                    Connection.Open();  
  9.              using (SqlDataReader myReader = myCommand.ExecuteReader())  
  10.                    {  
  11.                        DataTable dt = new DataTable();  
  12.                        dt.Load(myReader);  
  13.                        Connection.Close();  
  14.                         DataView dv = new DataView(dt);  
  15.                         dv.RowFilter = (("Name='ACVX'"));  
  16.                        var tableEnumerable = dv.ToTable().AsEnumerable();   
  17.                         
  18.                        var tableArray = tableEnumerable.ToArray();  
  19.                        return tableArray ;//Error  
  20.                    }  
  21.  }  
  22.    }  
  23.   
  24.        }  
I Want to load my datatable into an Var Array and Return the array .suggest some ideas to do my TASK..

Answers (3)