|
ADO.NET - How To: Add a Column to a Table |
|
|
Here is an example of adding a new column to an
existing table: |
private void btnDatabase_Click(object sender, EventArgs e)
{
using (SqlConnection connection =
new SqlConnection("Data Source=(local);" +
"Database='Exercise1';" +
"Integrated Security=yes;"))
{
SqlCommand command =
new SqlCommand("ALTER TABLE Customers " +
"ADD EmaillAddress varchar(100);",
connection);
connection.Open();
command.ExecuteNonQuery();
MessageBox.Show(
"A new column named \"EmailAddress\" has been added.");
}
}
|
|