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

Finally figured it out thanks to One Mad Monkey, but forgot quotes on my
- Solved - I Know they exist, but I haven't found a slider that
i have this problem: as i can add list to one list? i have
Okay, I have a strange problem. I wanted to run one of my programs
Finally deployed my ruby on rails 3.2 app but when trying to open it
Finally I managed to get pylucene working on my windows7 machine, Which raised a
I finally let windows nag me into upgrading from IE6 to 8. Now in
I finally have my C++ Builder 2010 installation the way I want it, with
I have a very dynamic SQL Server problem to solve. I am developing a
I have a scraper which visits many sites and finds upcoming events and another

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.