string strConn = "server=localhost;uid=sa;pwd=;DataBase=NorthWind;";
string strSql = "Select CustomerID, CompanyName From Customers";SqlDataAdapter da = new SqlDataAdapter(strSql,strConn);DataSet ds = new DataSet();
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(ds,"Customers");int max1 = ds.Tables["Customers"].Columns[0].MaxLength;
MessageBox.Show(max1.ToString());更详细的,看这个帖子。http://expert.csdn.net/Expert/TopicView3.asp?id=1340665

解决方案 »

  1.   

    对不起,我在问题中没表达清楚,是要得到DATASET中TABLE表上列的是大长度。
      

  2.   

    DataColumn对象的MaxLength属性,可以设置或取得文字字段的最大长度。
      

  3.   

    可我用MaxLength得到所有类型都是-1.我用的是XML。
      

  4.   

    我用的代码如下:
    oFileStream = new System.IO.FileStream( _TempFilePath, FileMode.Create, FileAccess.Write, FileShare.None );
    oStreamWriter = new System.IO.StreamWriter( oFileStream, System.Text.Encoding.Default );
    for (int i=0;i<=ds.Tables.Count-1;i++)
    {
    oStreamWriter.WriteLine("下面是表["+ds.Tables[i].TableName.ToString().Trim()+"]的内容");
    for (int ii=0;ii<=ds.Tables[i].Columns.Count-1;ii++)
    {
    oStreamWriter.Write(ds.Tables[i].Columns[ii].ColumnName.ToString());
    }
    oStreamWriter.WriteLine("");
    foreach (DataRow thItems in ds.Tables[i].Rows)
    {
    for (int ii=0;ii<=ds.Tables[i].Columns.Count-1;ii++)
    {
    int max1 = ds.Tables[i].Columns[ii].MaxLength;
    MessageBox.Show(max1.ToString());//这里得到的所有类型为-1
    oStreamWriter.Write(thItems[ii].ToString().PadRight(ds.Tables[i].Columns[ii].MaxLength,' ')+"  ");
    }
    oStreamWriter.WriteLine("");
    }
    }
    请指教。
      

  5.   

    DataColumn对象的MaxLength属性,只能设置或取得文字字段的最大长度,对于其他数据类型没有办法,只能判断数据类型啦