Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 16-Oct-12 20:24pm
v2

Hi,

I think it is better if you can google this simple question you can find number of ways

Try this link^
 
Share this answer
 
Comments
Sriram Mani 17-Oct-12 2:45am    
thanks adi,
Ill go through these links.
Linq is the answer. You can convert a DataTable to IEnumerable using the AsEnumerable method. Then, the ToArray() converts it to an array.

C#
//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.
JavaScript
var x = '<%=GetTabValue()%>';
  // called server side method
  alert(x);
 
Share this answer
 
v3
Comments
Sriram Mani 17-Oct-12 2:44am    
thanks sinhasourabh,
would you mind explain me a little briefly, because im new to c# and asp.net.
[no name] 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900