Dinesh Santhalingam

Dinesh Santhalingam

  • NA
  • 737
  • 367.4k

Load data table to array and return array using Jquery

Dec 28 2016 5:55 AM
  1. [System.Web.Services.WebMethod]  
  2. public Array 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 ;   
  20.                    }    
  21.  }    
  22.    }    
  23.     
  24.        }    
  1. //Front End  
  2.   
  3. <html>  
  4. <head/>  
  5. <script>  
  6.  PageMethods.loaddata(LoadSucc, LoadFail);  
  7.            function LoadSucc(obj) //obj is array returned from back end{obj-tablearray]  
  8.        {  
  9.                var goog = [];  
  10.                goog = Object.values(obj);  
  11.             //I want load the obj into my array goog.  
  12.            }  
  13.   
  14.            function LoadFail() {  
  15.                alert("Data missing");  
  16.            }  
  17. script>  
  18. <body/>  
  19. html>  
I want to Load my data table content to array and return array to front end using page methods..Suggest me some ideas..

Answers (7)