dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] VB 2010 - Renaming Columns in MSSQL Database

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2012
    Location
    Las Vegas, NV
    Posts
    41

    Resolved [RESOLVED] VB 2010 - Renaming Columns in MSSQL Database

    I am having an issue with renaming columns. My code is as follows:

    Code:
    Using m_cnInterval
        Using m_CMDInterval = New SqlCommand()
            m_CMDInterval.Connection = m_cnInterval
            m_CMDInterval.CommandText = "EXEC sp_rename '[" & strClassColumnName(intClassArrayPosition) & "]', '[" & strRenameClassColumn(intClassArrayPosition) & "]', 'COLUMN'"
            m_CMDInterval.CommandType = CommandType.Text
            m_CMDInterval.ExecuteNonQuery()
        End Using
    End Using
    I am getting an error message as follows:

    "Either the parameter @objname is ambiguous or the claimed @objtype (column) is wrong"

    I think this error is related to the way I am using my single quotes and brackets. Is there another syntax when using variables for column names?

    Thanks

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: VB 2010 - Renaming Columns in MSSQL Database

    sp_rename requires TableName.ColumnName for the first parameter. I'm assuming that the array value returns just the column name (or if not the problem is in the second parameter which doesn't require the table name).
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2012
    Location
    Las Vegas, NV
    Posts
    41

    Resolved Re: VB 2010 - Renaming Columns in MSSQL Database

    You are very correct. Thank you for your help!

    I ended up with the following:

    Code:
    m_CMDInterval.CommandText = "EXEC sp_rename 'Interval.[" & strClassColumnName(intClassArrayPosition) & "]', '" & strRenameClassColumn(intClassArrayPosition) & "', 'COLUMN'"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width