Wednesday, 21 December 2011

How to execute DDL command through ADO.Net ?

SqlConnection mySqlConnection = new SqlConnection("Data Source = LocalServer;Initial Catalog=dbAccount;Integrated Security=True;");

SqlCommand mySqlCommand = mySqlConnection.CreateCommand();

mySqlCommand.CommandText = "CREATE TABLE MyEmployee (ID int CONSTRAINT PK_Persons PRIMARY KEY, FirstName nvarchar(15) NOT NULL, LastName nvarchar(15) NOT NULL, DateOfBirth datetime )";

mySqlConnection.Open();

int result = mySqlCommand.ExecuteNonQuery();
        
mySqlConnection.Close();

No comments:

Post a Comment