首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > SQL问题
【标  题】:SQL问题
【关键字】:SQL
【来  源】:http://blog.csdn.net/a450987/archive/2007/04/19/1570414.aspx

SQL问题

SQL问题
 
SQL 数据库后缀MSF,代码:
数据表:
CREATE TABLE CateTable (

[ID] [int] IDENTITY (1, 1) NOT NULL ,


[CateName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,


[RootID] [int] NOT NULL ,


[ParentID] [int] NOT NULL

)
GO

存储过程:
CREATE PROCEDURE CateTable_GetList AS
BEGIN

Select


CateID,


CateName,


RootID,


ParentID


From


CateTable


Order By


CateID,RootID,ParentID

END

代码:
        private void MainForm_Load(object sender, EventArgs e)
        {
            //从数据库中读取数据
            SqlConnection con = new SqlConnection(ConnString.ConStr);
            SqlCommand cmd = new SqlCommand("CateTable_GetList", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            try
            {
            sda.Fill(ds);
            }
            catch
            {
            }
            finally
            {
            cmd = null;
            con.Close();
            }
            //往TreeView中添加树节点
            //添加根节点
            TreeNode tn = new TreeNode();
            tn.Text = "种类";
            tn.Name = "0";//Name作为ID
            tn.Tag = "0";//Tag作为RootID
            tn.ImageIndex = 0;
            tn.SelectedImageIndex = 0;
            tv.Nodes.Add(tn);//该TreeView命名为tv
            tv.SelectedNode = tv.TopNode;
            //把其他节点加上去
            if (ds != null)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    tn = new TreeNode();
                    tn.Text = dr["CateName"].ToString();
                    tn.Name = dr["CateID"].ToString();//Name作为CateID
                    tn.Tag = dr["RootID"].ToString();//Tag作为RootID
                    tn.ImageIndex = 1;
                    tn.SelectedImageIndex = 1;
              //判断是否为主节点
                    if (dr["CateID"].ToString() == dr["RootID"].ToString())
                    {
              //主节点
                        tv.SelectedNode = tv.TopNode;
                    }
                    else
                    {
              //其他节点
                        if (tv.SelectedNode.Name != dr["parentID"].ToString())
                        {
                            TreeNode[] tn_temp = tv.Nodes.Find(dr["parentID"].ToString(), true);
                            if (tn_temp.Length > 0)
                            {
                                tv.SelectedNode = tn_temp[0];
                            }
                        }
                    }
                    tv.SelectedNode.Nodes.Add(tn);
                }
                tv.ExpandAll();//展开TreeView
                tv.SelectedNode = tv.TopNode;
            }
        }

foreach (DataRow dr in ds.Tables[0].Rows)这里出错
提示:确保列表中的最大索引小于列表的大小
未处理 System.IndexOutOfRangeException
  Message="无法找到表 0。"
  Source="System.Data"
  StackTrace:
      在 System.Data.DataTableCollection.get_Item(Int32 index)
      在 w.MainForm.MainForm_Load(Object sender, EventArgs e) 位置 D:\1\w\MainForm.cs:行号 52
      在 System.Windows.Forms.Form.OnLoad(EventArgs e)
      在 System.Windows.Forms.Form.OnCreateControl()
      在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
      在 System.Windows.Forms.Control.CreateControl()
      在 System.Windows.Forms.Control.WmShowWindow(Message& m)
      在 System.Windows.Forms.Control.WndProc(Message& m)
      在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
      在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
      在 System.Windows.Forms.Form.WmShowWindow(Message& m)
      在 System.Windows.Forms.Form.WndProc(Message& m)
      在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
      在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
      在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      在 System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
      在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
      在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
      在 System.Windows.Forms.Control.set_Visible(Boolean value)
      在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
      在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
      在 System.Windows.Forms.Application.Run(Form mainForm)
      在 w.Program.Main() 位置 D:\1\w\Program.cs:行号 17
      在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
      在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      在 System.Threading.ThreadHelper.ThreadStart()
达人帮帮
 
【转载】SQL Server中索引使用及维护:【上一篇】
Oracle之PL/SQL学习笔记(3):【下一篇】
【相关文章】
  • 【转载】SQL Server中索引使用及维护
  • 改变SQL Server 2005 Express 的身份验证方式
  • SQL语句中CASE When的用法 相当于普通编程下的IF Else语句
  • Review SQL- neglected SQL Keywords
  • SQL Server 存储过程嵌套示例
  • Excel导入SQL数据库完整代码
  • 一步一步设置 PHP 和 MySQL 开发环境
  • 领导汇报_数据统计_sql.txt
  • mysql cluster 运用disk data storage 的测试
  • 安装linux+apache+mysql+php
  • 【随机文章】
  • asp.net ajax应用技巧之方法的重载
  • Spring in Action 学习笔记—第四章 征服数据库
  • 《Google Hacks》读书笔记
  • Painter 7 笔刷介绍
  • java.lang.OutOfMemoryError的解決方法集
  • vim使用
  • DB2 基础:日期和时间的使用
  • 平行的曲
  • 贪吃蛇 J2ME 的实现 (简单程序,练练手艺) 0.1版本
  • Eclipse开发书籍推荐
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.