ADO.Net : Get table definition from SQL server tables

后端 未结 5 613
梦毁少年i
梦毁少年i 2021-01-12 20:37

I am using C# to write a method that returns the following information about a table: column names, column types, column sizes, foreign keys.

Can someone point me in

5条回答
  •  情书的邮戳
    2021-01-12 20:51

    You can use the SqlDataAdapter.FillSchema() method.

    Alternatively you can use the SqlDataAdapter.Fill() method after setting the MissingSchemaAction property of the SqlDataAdapter to AddWithKey. But if you only want the schema you must ensure that your query returns no rows. This can be accomplished by adding a statement like WHERE 1=2 to your query.

提交回复
热议问题