Home

ADO.NET - How To: Rename a Column

     

Introduction

Here is an example of renaming an existing column of a table in a Microsoft SQL Server database:

private void btnDatabase_Click(object sender, EventArgs e)
{
string strConnection = "sp_rename 'StaffMembers.FullName',
		        'EmployeeName', 'COLUMN';";
    SqlConnection conDatabase = new 
	SqlConnection("Data Source=(local);" +
		      "Database='Countries2';" +
		      "Integrated Security=yes");
    SqlCommand cmdDatabase = new SqlCommand(strConnection, conDatabase);

    conDatabase.Open();

    cmdDatabase.ExecuteNonQuery();
    conDatabase.Close();
}
 
 

Home Copyright © 2011 C#Key