使用PropertyDescriptor应该可以。

解决方案 »

  1.   

    这个 DataType是不是返回了System.Type类型,不可以转换成SqlDbType类型的。
      

  2.   

    各位朋友,我现在是想写一个自动生成SqlParameter的模块,其中建立SqlParameter的时候,需要指定参数的SqlDbType。因为考虑自动化,所以不能人为地打开数据库去看结构,也不存在将结构写死的可能。CommandBuilder自动生成的Command属性中,可以找到对应列的SqlDbType。但是我想不通过CommandBuilder来得到这个SqlDbType。请各位帮忙!
      

  3.   

    this.sqlConnection1.Open();
    this.sqlDataAdapter1.SelectCommand.CommandText = "sp_help table1";
    DataSet ds = new DataSet();
    this.sqlDataAdapter1.Fill(ds,"table1");
    this.dataGrid1.DataSource = ds.Tables[1].DefaultView;
    this.sqlConnection1.Close();
    for(int i=0;i<ds.Tables[1].Rows.Count;i++)
    {
    this.listBox1.Items.Add(ds.Tables[1].Rows[i]["type"].ToString());
    }
      

  4.   

    cqnimin() 理解把我的意思对了。
    但是还有一点点小问题:能否直接得到对应的SqlDbType枚举值?最好不要自己用分支结构来判断。另外,能否不通过sp_help这个存储过程,而直接用dotNet的语句得出?
    先给帖子涨分先,请朋友们继续回答!
      

  5.   

    嘿嘿。更正:cqnimin() 把我的意思理解对了。
      

  6.   

    this.sqlConnection1.Open();
    this.sqlDataAdapter1.SelectCommand.CommandText = "select * from table1 where 1=2";
    DataSet ds = new DataSet();
    this.sqlDataAdapter1.FillSchema(ds,System.Data.SchemaType.Mapped);这样用DataColumn.DateType应该可以了
      

  7.   

    to:lx1920(怀念1919年) 
    先表示感谢!
    但我试验了FillSchema的多个重载版本,都没有成功。不知道我错在什么地方……
      

  8.   

    你可以写查询语句操作systypes,syscloumns,sysobjects这几个表它们之间的关系
    你查一下这几个表的说明就可以了
      

  9.   

    奇怪的是,CommandBuilder自动生成的Command对象的Parameter,是自带了准确的SqlDbType的,它不知内部是怎么分析出来的?
      

  10.   

    执行
    exec sp_MShelpcolumns 'yourtable'
    啥都有了
      

  11.   

    public DataSet GetTableColums()
    {
    DataSet ColumsDs=new DataSet();
    string strSQL="SELECT SYS.USER_COL_COMMENTS.TABLE_NAME as TABLE_NAME,SYS.USER_COL_COMMENTS.COLUMN_NAME as COLUMN_NAME, SYS.USER_COL_COMMENTS.COMMENTS as COMMENTS FROM SYS.USER_COL_COMMENTS WHERE NOT (SYS.USER_COL_COMMENTS.COMMENTS IS NULL)";
    ColumsDs=this.ExecuteSqlReturnDataSet(strSQL,"USER_COL_COMMENTS");
    return ColumsDs;
    }

    /// <summary>
    /// 获取字段类型
    /// </summary>
    /// <param name="ColumsTypeDs">字段类型DataSet</param>
    public DataSet GetColumsType()
    {
    oracle,可以这样 DataSet ColumsTypeDs=new DataSet();
    string strSQL="SELECT SYS.USER_TAB_COLUMNS.TABLE_NAME as TABLE_NAME,SYS.USER_TAB_COLUMNS.COLUMN_NAME as COLUMN_NAME,SYS.USER_TAB_COLUMNS.DATA_TYPE as DATA_TYPE FROM SYS.USER_TAB_COLUMNS";
    ColumsTypeDs=this.ExecuteSqlReturnDataSet(strSQL,"USER_TAB_COLS");
    return ColumsTypeDs;
    }