Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
Hi all,
I want to know whether is it possible to get data from a ms access database and store the values into an array created inside a script so that i can use the values for form validation. If possible, please guide me how.
 
Thanks in advance
Posted 16-Oct-12 20:23pm
Edited 16-Oct-12 20:24pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Linq is the answer. You can convert a DataTable to IEnumerable using the AsEnumerable method. Then, the ToArray() converts it to an array.
 
//1. Fetch data from the access and store it in DataTableName.

// 2. convert datatable into array.
var tableEnumerable = DataTableName.AsEnumerable();
tableArray = tableEnumerable.ToArray(); 
 
// 3.1 srealize your code for JS, create seperate function for this. do this in your .ASPX.CS page

 protected string GetTabValue() 
    {         // you can do more processing here         ....         ....         // use serializer class which provides serialization and deserialization functionality for AJAX-enabled applications.  
        JavaScriptSerializer jSerializer=new JavaScriptSerializer(); 
        // serialize your object and return a serialized string   
      return jSerializer.Serialize(tableArray );
     } 
//3.2 Acces this function in your js and do what you want to do . this should be in you .aspx page.
  var x = '<%=GetTabValue()%>'; 
    // called server side method 
    alert(x); 
 
  Permalink  
v3
Comments
Sriramdeve at 17-Oct-12 2:44am
   
thanks sinhasourabh,
would you mind explain me a little briefly, because im new to c# and asp.net.
sinhasourabh at 17-Oct-12 2:53am
   
I assumed that you are using .net 3.5 or above framework.
What we need to do is
1. fetch data from your database using oledb and store it in a datatable. (pls google this, if you dont know how to do it.)
2. convert you table table into array.
3. access your array from JS.
 
please find relative code in above answer, i have updated the code with points.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
I think it is better if you can google this simple question you can find number of ways
 
Try this link^
  Permalink  
Comments
Sriramdeve at 17-Oct-12 2:45am
   
thanks adi,
Ill go through these links.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 768
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100