asp.net 中怎么样在客户端的javascript中读取数据库表
希望各位哥哥姐姐帮帮忙
很着急

解决方案 »

  1.   

    可能吗?那B/S结构和C/S结构还有什么区别。还有什么安全性可言
      

  2.   

    http://blog.sina.com.cn/s/blog_4c7d5a300100ava1.html参考一下吖
      

  3.   

    javascript可以连接你的客户端数据库
    可以使用Ajax可以给服务器发请求,让服务器端程序连接数据库
      

  4.   

    http://blog.sina.com.cn/s/blog_4c7d5a3001008aip.html
    http://blog.sina.com.cn/s/blog_4c7d5a3001008aiw.html
      

  5.   

    对 ajax可以 并不复杂 
      

  6.   

    用ajax 
    或者你用js写ado 那就是asp了
    ---------
    LZ的头像是你本人吗,好漂亮哦
      

  7.   

    我不太会用AJAX
    哪位好心的哥哥姐姐,可不可以给我做个样例看看
    发发源代码
      

  8.   

    当然是写webservice了!js不用代理是无法和数据库交流的!
      

  9.   

    使用ASP.NET AJAX来实现吧,很简单using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    using System.Web.Services;
    using System.Threading;public partial class Default2 : System.Web.UI.Page
    {
        string ConStr = ConfigurationManager.ConnectionStrings["NorthwindConnection"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }    private void BindData()
        {
            string Sql = "SELECT TOP 10 * FROM customers";
            using (SqlConnection Con = new SqlConnection(ConStr))
            {
                using (SqlCommand Cmd = new SqlCommand(Sql, Con))
                {
                    Con.Open();
                    DataTable dt = new DataTable();
                    using (SqlDataReader Dr = Cmd.ExecuteReader())
                    {
                        dt.Load(Dr);
                        gvNorth.DataSource = dt;
                        gvNorth.DataBind();
                    }
                }
            }
        }    [WebMethod]
        public static string GetData()
        {
            Thread.Sleep(10000);
            //return "this is tommy test";
            string ConStrs = ConfigurationManager.ConnectionStrings["NorthwindConnection"].ConnectionString;
            string Sql = "SELECT TOP 3 CustomerID,CompanyName,ContactName FROM customers ";
            string Result = string.Empty;
            using (SqlConnection Con = new SqlConnection(ConStrs))
            {
                using (SqlCommand Cmd = new SqlCommand(Sql, Con))
                {
                    Con.Open();
                    DataTable dt = new DataTable();
                    using (SqlDataReader Dr = Cmd.ExecuteReader())
                    {
                        while (Dr.Read())
                        {
                            Result += Dr[0].ToString() + ";";
                            
                        }                }
                }
            }
            return Result;
        }
        
        // 供前台AJAX调用
        [WebMethod]
        public static DataTable GetDataTable()
        {
            Thread.Sleep(10000);
            string ConStrs = ConfigurationManager.ConnectionStrings["NorthwindConnection"].ConnectionString;
            string Sql = "SELECT TOP 3 CustomerID,CompanyName,ContactName FROM customers";
            DataTable ResultTable = new DataTable();
            DataTable OrderTable = new DataTable();
            using (SqlConnection Con = new SqlConnection(ConStrs))
            {
                using (SqlCommand Cmd = new SqlCommand(Sql, Con))
                {
                    Con.Open();
                    DataTable dt = new DataTable();
                    using (SqlDataReader Dr = Cmd.ExecuteReader())
                    {
                        ResultTable.Load(Dr);
                    }
                }
            }
            return ResultTable;
        }
    }<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Trace="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <style type="text/css">
            .Show
            {
                display: block;
            }
            .Hiden
            {
                display: none;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
            <script type="text/javascript">
            Sys.Application.add_load(onload);
            Sys.Application.add_init();
            function onload()
            {
                PageMethods.GetData(onInvokeSucced);
            }
            
            function onInvokeSucced(result)
            {
                if(result != null)
                {
                    $get("top").className = "Show";
                    $get("img").className = "Hiden";
                    $get("top").innerHTML = result.toString();
                }
                else
                {
                      $get("top").className = "Hiden";
                      $get("img").className = "Show";
                }
            }
        </script>
        <div id="top" class="Hiden">
            <asp:Label ID="lblTest" runat="server"></asp:Label>
        </div>
        <div id="img" style="margin-left:500px;">
            <img src="Img/ajax-loader.gif" alt="waiting" />
        </div>
        <div>
            <asp:GridView ID="gvNorth" runat="server">
            </asp:GridView>
        </div>
        </form>
    </body>
    </html>
      

  10.   

    谢谢10楼的朋友了
    不过还有一个问题要请教
    好是关于AJAX
    有时间加我MSN:[email protected]