无法将数据库表名称弹出为树视图中的父节点 [英] Unable to popluate the database table name as parent node in treeview

查看:109
本文介绍了无法将数据库表名称弹出为树视图中的父节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Title="" Language="C#"  AutoEventWireup="true" CodeFile="ScriptFile.aspx.cs" Inherits="ScriptFile" %>

<!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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:treeview ID="Treeview1" runat="server"></asp:treeview>
</div>
</form>
</body>
</html>







using System;
using System.Data;
using System.IO;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;

public partial class ScriptFile : System.Web.UI.Page
{
    string str;
    MySqlCommand com;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        bindtreeview();
    }

    void bindtreeview()
    {

        MySqlConnection con = new MySqlConnection("Data Source=localhost;Database=utaf;User ID=root;Password=admin;");


        con.Open();
        str = "Select * from scriptgeneratetable";
        com = new MySqlCommand(str, con);
        MySqlDataReader reader = com.ExecuteReader();
        com.Dispose();
        string[,] ParentNode = new string[100, 2];
        int count = 0;
        while (reader.Read())
        {
            ParentNode[count, 0] = reader.GetValue(reader.GetOrdinal("Foldername")).ToString();
            ParentNode[count++, 1] = reader.GetValue(reader.GetOrdinal("textfilename")).ToString();

             
        }
        reader.Close();
        
    }
     
    protected void MyTree_SelectedNodeChanged(object sender, EventArgs e)
    {

    }
}

推荐答案

假设您要填充当前数据库中的所有用户表,您应该使用以下查询 -



SELECT * FROM SYSOBJECTS WHERE xtype ='U'
Assuming that you want to populate all the User Tables in your current database, you should use the following query -

SELECT * FROM SYSOBJECTS WHERE xtype='U'


这篇关于无法将数据库表名称弹出为树视图中的父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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