locked
Create Table using Enterprise Library RRS feed

  • Question

  • User395413141 posted

    Hi,

    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

    Thursday, March 17, 2011 7:41 AM

Answers

  • User1052258516 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 19, 2011 1:04 PM

All replies

  • User1052258516 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 19, 2011 1:04 PM
  • User-2070745589 posted

    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

     

    Monday, February 18, 2013 11:20 PM