I have a method through which i am creating a Table in DB as shown below,
public void CreateTable(List<string开发者_高级运维> columnNames, string tableName)
{
string connectionString = Utility.ReadDataFromConfig("ConnectionTest");
using (var connection = new SqlConnection(connectionString))
{
var server = new Server(new ServerConnection(connection));
var db = server.Databases["GlassLookUp"];
var newTable = new Table(db, tableName);
var idColumn = new Column(newTable, "ID") { DataType = DataType.Int, Nullable = false };
newTable.Columns.Add(idColumn);
foreach (var titleColumn in from temp in columnNames
where temp != string.Empty
select new Column(newTable, temp) { DataType = DataType.VarChar(500), Nullable = true })
{
newTable.Columns.Add(titleColumn);
}
newTable.Create();
}
}
I wanted the above method to be changed, so that Enterprise library is use. I have already used Enterprise library to execute stored procedures, but i dont know how to use Enterprise library to Create a Table.
Thanks
It looks like your code is using SQL Server Management Objects (SMO). I don't think you can use SMO in a useful way with Enterprise Library Data Access Application Block. The best that you could do would be to get the connection:
public void CreateTable(List<string> columnNames, string tableName)
{
Database database = DatabaseFactory.CreateDatabase("ConnectionTest");
string connectionString = database.ConnectionString;
//...
newTable.Create();
}
But that is not adding very much value. :)
精彩评论