本文介绍了不能在秒时使用asp.net C#查询访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始时,我可以获取我在droplist值中下载的数据,但是当我想选择另一个值时,它没有显示我选择的表数据。

i页面加载时将表名放在droplist中:

in the beginning, i can get the data which i sleceted in droplist value,but when i want to select another value,it didn't show up the table data where from i selected.
i put table name in droplist when page load:

string dataSource = Server.MapPath("MIStest.mdb");
        string connectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dataSource;
        OleDbConnection conn =
            new OleDbConnection(connectionStr);
        OleDbCommand command =
            new OleDbCommand();
        //get table name
        command.Connection = conn;
        conn.Open();

        DataTable tableName = new DataTable();
        tableName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {Nothing, Nothing, Nothing, "TABLE"});

        DropDownList1.DataSource = tableName;
        DropDownList1.DataTextField = "table_name";
        DropDownList1.DataValueField = "table_name";
        DropDownList1.DataBind();

        conn.Close();





那么这是当droplist更改选择值时:



then this is when droplist change select value:

Response.Write("尚未連線..<br>");
        string dataSource = Server.MapPath("MIStest.mdb");
        string connectionStr = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + dataSource;
        OleDbConnection conn =
            new OleDbConnection(connectionStr);
        conn.Open();

        //do query and search
        string query = "SELECT * FROM [" + DropDownList1.SelectedValue + "]";
        OleDbCommand command = new OleDbCommand(query, conn);
        OleDbDataReader dataR = command.ExecuteReader();

        Response.Write("<table border='2'>");
        int rowNum = dataR.VisibleFieldCount;
        
        //get cloum
        
        Response.Write("<tr>");
        for (int j = 0; j < rowNum; j++)
        {
            Response.Write("<td>" + dataR.GetName(j));
        }

        do
        {
            int count = dataR.FieldCount;
            while (dataR.Read())
            {
                Response.Write("<tr>");
                for (int i = 0; i < count; i++)
                {
                    Response.Write("<td>" + dataR.GetValue(i));

                }
            }
        } while (dataR.NextResult());
        Response.Write("</table");

       conn.Close();

推荐答案


这篇关于不能在秒时使用asp.net C#查询访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 06:02