//获取数据表字段定义设置信息
string MyConnectionString="Data Source=(local);Integrated Security=SSPI; Initial Catalog = NorthWind";
string MySQL = "Select * From Customers";
SqlConnection MyConnection=new SqlConnection(MyConnectionString);
try
{
MyConnection.Open();
SqlCommand MyCommand=new SqlCommand(MySQL,MyConnection);
SqlDataReader MyReader = MyCommand.ExecuteReader();
DataTable MyTable = MyReader.GetSchemaTable();
int MyCount=1;
string MyInfo="";
foreach (DataRow MyRow in MyTable.Rows)
{
MyInfo+="\n第"+MyCount+"个字段定义设置信息如下:\n";
foreach (DataColumn MyColumn in MyTable.Columns)
{
MyInfo+="\n"+MyColumn.ColumnName+ " = " + MyRow[MyColumn];
}
MyCount++;
}
MyReader.Close();
this.richTextBox1.Text = MyInfo;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"信息提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
MyConnection.Close();
}