简体   繁体   中英

there is an error when I try to make sql query to rename column name through asp.net

now, I working on asp.net. and I only put textbox and rename button on the web form. I want now to enter new name of one column (which is called skill1) in the text box then click rename button to rename this column please see my code below. there is an error in the last line. So, it is not work. I don't know what is the problem. please try to help me.

string conString = @"Data Source=FATTO-TOSH\SQLEXPRESS;Initial Catalog=Positions;Integrated Security=True";
    SqlConnection c = new SqlConnection(conString);
    string sql = "EXEC sp_RENAME 'PositionsReq.skill1' ,  '"+name.Text+"', 'COLUMN'";
    c.Open();
    SqlCommand cmd = new SqlCommand(sql, c);
    cmd.Parameters.Add("@name", SqlDbType.VarChar);
    cmd.ExecuteNonQuery();
using (var con = new SqlConnection(conString))
{
    var cmd = new SqlCommand("sys.sp_rename", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@objname", coulmnName)
        .SqlDbType = SqlDbType.NVarChar;
    cmd.Parameters.AddWithValue("@newname", name.Text)
        .SqlDbType = SqlDbType.NVarChar;
    cmd.ExecuteNonQuery();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM