Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6164761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:02:55+00:00 2026-05-23T22:02:55+00:00

I finally solved one problem but now i have another. I found out how

  • 0

I finally solved one problem but now i have another. I found out how to get the name of the current field my selector is on, but now when I want to use an update command for it, they will not let me set a parameter. Heres some code…

    private void dgv_DataLookup_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {

        DialogResult dr;
        dr = MessageBox.Show("Are you sure you want to edit this field?", "Edit Cell", MessageBoxButtons.YesNo);

        if (dr == DialogResult.Yes)
        {
            string myCell = dgv_DataLookup.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            string myIndex = dgv_DataLookup.CurrentCell.OwningRow.Cells[6].Value.ToString();
            string myColumn = dgv_DataLookup.CurrentCell.OwningColumn.HeaderCell.Value.ToString();
            myColumn.Trim();

            da.UpdateCommand = new OleDbCommand("UPDATE tbl_Orders SET @myColumn = @myCell WHERE oid = @myIndex", cs);
            da.UpdateCommand.Parameters.Add("@myColumn", OleDbType.VarChar).Value = myColumn;
            da.UpdateCommand.Parameters.Add("@myCell", OleDbType.VarChar).Value = myCell;
            da.UpdateCommand.Parameters.Add("@myIndex", OleDbType.Integer).Value = myIndex;

            cs_Execute("UPDATE");

        }
    }

when I change myColumn to the actual column, say itemNum, it works fine. However, the error was Cannot update ‘@myColumn’; field not updateable

I also had a message box showing me the value of myColumn and it was the correct value. I was just wondering if this was legal, seting a parameter to a parameter. If not, then I’ll just have to update all the rows. Thanks!

p.s. cd_Execute is just like cs.Open() da.UpdateCommand.ExecuteNonQuery() cs.Close()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:02:57+00:00Added an answer on May 23, 2026 at 10:02 pm

    You cannot have dynamic column names in parametrized queries. You will need to resort to dynamic SQL.

    This will do what you want, though open to SQL Injection:

    da.UpdateCommand = new OleDbCommand(string.Format("UPDATE tbl_Orders SET {0} = @myCell WHERE oid = @myIndex", myColumn), cs);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I finally found out the difference between UTC and GMT by making the effort
I finally have a hardware guy that is insterested in controlling the firmware. This
I'm finally getting my team to embrace source code management now that we're working
I have finally finished my web site. I published it, and I was surprised
Since there is no finally in C++ you have to use the RAII design
I have finally got the green light to use Memcached in our project (after
Here is the problem: we have lots of Javascripts and lots of CSS files,
I have a complex SQL problem in MS SQL Server, and in drawing on
After searching a lot i did not get any answers and finally i had
I'm trying to solve the problem of the second day but with no success

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.