C# 用C语言获取数据库表#
我正在尝试按照ObjectType获取数据库表,如何实现这一点? 到目前为止,我试过这种方法C# 用C语言获取数据库表#,c#,ado.net,C#,Ado.net,我正在尝试按照ObjectType获取数据库表,如何实现这一点? 到目前为止,我试过这种方法 public void GetTableByObjectType(string ObjectType) { SqlConnection conn = new SqlConnection( "Data Source=Local;Initial Catalog=myConnection;User ID=sa;Password=12345"); D
public void GetTableByObjectType(string ObjectType) {
SqlConnection conn = new SqlConnection(
"Data Source=Local;Initial Catalog=myConnection;User ID=sa;Password=12345");
DataTable t = conn.GetSchema("Objectype");
这段代码将帮助您从试图访问的数据库中获取所有表
string SQLExpression = "SELECT * FROM SYS.Tables Order By Name";
SqlConnection conn = new SqlConnection(
"Data Source=Local;Initial Catalog=myConnection;User ID=sa;Password=12345");
SqlDataAdapter adp = new SqlDataAdapter(SQLExpression, cn);
DataSet ds = new DataSet();
adp.Fill(ds, "SystemData");
这段代码将帮助您从试图访问的数据库中获取所有表
string SQLExpression = "SELECT * FROM SYS.Tables Order By Name";
SqlConnection conn = new SqlConnection(
"Data Source=Local;Initial Catalog=myConnection;User ID=sa;Password=12345");
SqlDataAdapter adp = new SqlDataAdapter(SQLExpression, cn);
DataSet ds = new DataSet();
adp.Fill(ds, "SystemData");
在本例中,您将获得数据库表的模式:
String ObjectType = "Tables"; //collectionName argument to get Tables
String[] tableRestrictions = new String[4];
tableRestrictions[2] = "TableYouWant"; //name of the table whose get the schema
DataTable courseTableSchemaTable = conn.GetSchema(ObjectType, tableRestrictions);
可以对表集合使用四个限制,因此应该创建一个4成员数组。
对于数组表限制
:
- 0-成员代表目录李>
- 1-成员代表模式李>
- 2-成员表示表名李>
- 3-member表示表类型
另请参见:在本例中,您可以获得数据库表的模式:
String ObjectType = "Tables"; //collectionName argument to get Tables
String[] tableRestrictions = new String[4];
tableRestrictions[2] = "TableYouWant"; //name of the table whose get the schema
DataTable courseTableSchemaTable = conn.GetSchema(ObjectType, tableRestrictions);
可以对表集合使用四个限制,因此应该创建一个4成员数组。
对于数组表限制
:
- 0-成员代表目录李>
- 1-成员代表模式李>
- 2-成员表示表名李>
- 3-member表示表类型
另请参见:您希望仅获取数据库中的表列表?我相信GetSchema将获取DB->all tables、all View等模式。您希望仅获取数据库中的表列表?我相信GetSchema将获取DB->all tables、all View等模式。。