这个问题很多人都问过,包括我,有人告诉我用什么col.MaxLenth之类,但总是返回-1,帮你UP一下,希望能解决。

解决方案 »

  1.   

    select c.name as tbName,a.name as zdName,ltrim(b.name) as typeName,isnull(a.prec,0) as prec,isnull(a.scale,0) as scale,a.isnullable from syscolumns a left join sysTypes b on a.xtype=b.xtype  left join sysobjects c on a.id=c.id where a.id in (select id from sysobjects where type ='u' and name like TABLENAME ) order by c.name,a.name用表名替换TABLENAME,可以得到该表的每个字段的信息。
      

  2.   

    this.sqlDataAdapter1.FillSchema(this.dataSet11,SchemaType.Mapped);//加上这句
    for ( int i= 0; i<= this.dataSet11.Tables[0].Columns.Count-1; i++ )
    {
    MessageBox.Show(this.dataSet11.Tables[0].Columns[i].MaxLength.ToString());
    }