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
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
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("");
}
}
请指教。