解决方法
要获得FK和Schema,您应该能够使用:
DA.FillSchema() DS.Table("Name").PrimaryKey
private void LoanSchema() { private List<String> tablesList = new List<String>(); private Dictionary<String,String> columnsDictionary = new Dictionary<String,String>(); string connectionString = "Integrated Security=sspI;" + "Persist Security Info = False;Initial Catalog=northwind;" + "Data Source = localhost"; sqlConnection connection = new sqlConnection(); connection.ConnectionString = connectionString; connection.open(); sqlCommand command = new sqlCommand(); command.Connection = connection; command.CommandText = "exec sp_tables"; command.CommandType = CommandType.Text; sqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) tablesList.Add(reader["TABLE_NAME"].ToString()); } reader.Close(); command.CommandText = "exec sp_columns @table_name = '" + tablesList[0] + "'"; command.CommandType = CommandType.Text; reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) columnsDictionary.Add(reader["COLUMN_NAME"].ToString(),reader["TYPE_NAME"].ToString()); } }
原文地址:https://www.jb51.cc/csharp/98158.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。