我在treeview为什么只显示了数据库的第一条记录,其他为什么没有显示出来

felix61 2003-07-22 11:22:25
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{
private const string Stock_Image_Url = "images/mediastock.gif";
private const string Sort_Image_Url = "images/mediastock.gif";
private System.Windows.Forms.TreeView tvw;
private System.Windows.Forms.ImageList imageList1;
private System.ComponentModel.IContainer components;
public Form1()
{

InitializeComponent();
this.CreateTreeView();
}

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void CreateTreeView()
{
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\TaxLaw\\TaxLaw\\feitiumjoy.mdb";
tvw.Nodes.Clear() ;
string sql = "SELECT * FROM Type ";
OleDbConnection conn = new OleDbConnection() ;
conn.ConnectionString = connStr ;
OleDbDataAdapter oleDa = new OleDbDataAdapter(sql,connStr);
DataSet ds = new DataSet();
oleDa.Fill(ds,"type");
oleDa.SelectCommand.CommandText = "SELECT * FROM SmallClass";
oleDa.Fill(ds,"smallclass");
conn.Close();
DataColumn primaryKey = ds.Tables["SmallClass"].Columns["SmallClassID"];
ds.Tables["smallclass"].PrimaryKey = new DataColumn[]{primaryKey};
TreeNode node = GetRootNode(ds.Tables["type"],ds.Tables["smallclass"]);
if(node != null)
tvw.Nodes.Add(node);
node.Expand();
}
private TreeNode GetRootNode(DataTable dtType,DataTable dtSmallClass)
{
//调用函数前必须检查是否有记录
if(dtType.Rows.Count > 0)
{

TreeNode stockNode = new TreeNode();
stockNode.Text = dtType.Rows[0]["TypeName"].ToString();
stockNode.SelectedImageIndex = 1;
return stockNode;
}
else
{
return null;
}
}

}
}
...全文
17 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
C#

10.8w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2003-07-22 11:22
社区公告

让您成为最强悍的C#开发者