从数据库获取数据并将其存储到asp.net中的数组中 [英] getting data from a database and store it into an array in asp.net

查看:257
本文介绍了从数据库获取数据并将其存储到asp.net中的数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我想知道是否可以从ms访问数据库中获取数据并将这些值存储到在脚本内部创建的数组中,以便我可以将这些值用于表单验证.如果可能的话,请指导我.

在此先感谢

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

推荐答案

Linq是答案.您可以使用AsEnumerable方法将DataTable转换为IEnumerable.然后,ToArray()将其转换为数组.

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在您的js中访问此函数,然后执行您想做的事情.这应该在您的.aspx页面中.


//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);




我认为,如果您可以用Google搜索这个简单的问题,那就可以找到很多方法了,

尝试
Hi,

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

Try this link^


这篇关于从数据库获取数据并将其存储到asp.net中的数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆