publicvoid 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 infrom temp in columnNames
where temp != string.Empty
selectnew Column(newTable, temp) { DataType = DataType.VarChar(500), Nullable = true })
{
newTable.Columns.Add(titleColumn);
}
newTable.Create();
}
}
</div>
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.
From what I understand about the Enterprise Library (database) it is for data access only not for manupulating the database schema, you would need to keep using SQL DMO/SMO like you are.
Please mark the most helpful post(s) as Answer Blog | I need more space:DropBox Referral
Marked as answer by uthappa on Mar 21, 2011 09:26 AM
uthappa
Member
51 Points
21 Posts
Create Table using Enterprise Library
Mar 17, 2011 11:42 AM|LINK
Hi,
I have a method through which i am creating a Table in DB as shown below,
<div style="font-weight: inherit; font-style: inherit; font-family: inherit; outline-width: 0px; outline-style: initial; outline-color: initial; color: black; background-color: white; padding: 0px; margin: 0px; border: 0px initial initial;"> </div>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
enterprise
whighfield
Star
11721 Points
1859 Posts
Re: Create Table using Enterprise Library
Mar 19, 2011 05:04 PM|LINK
From what I understand about the Enterprise Library (database) it is for data access only not for manupulating the database schema, you would need to keep using SQL DMO/SMO like you are.
Blog | I need more space:DropBox Referral
wajirasomara...
Member
2 Points
1 Post
Re: Create Table using Enterprise Library
Feb 19, 2013 03:20 AM|LINK
We were able to create tables , create schemas and logins through Enterprise library. Didn't experience such issue.
Using cmd As DbCommand = MyDB.GetSqlStringCommand("create login XYZLOGIN with password = 'abc123@@@' ")
MyDB.ExecuteNonQuery(cmd)
End Using