3
Reply

Data table to array and return array

Dinesh Santhalingam

Dinesh Santhalingam

Dec 28 2016 1:10 AM
334
  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..

Upload Source Code  Select only zip and rar file.
Answers (3)