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 9169603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:54:07+00:00 2026-06-17T15:54:07+00:00

At first I tried this: string set = ; for (int i = 1;

  • 0

At first I tried this:

    string set = "";
    for (int i = 1; i < result.Count; i++)
    {
        if ((fieldtypes[i] == "System.Int32"))
        {
            set += fields[i] + "=" + result[i] + ", ";
        }
        else if (fieldtypes[i] == "System.String")
        {
            set += fields[i] + "='" + result[i] + "', ";
        }
        else if (fieldtypes[i] == "System.Boolean")
        {
            set += fields[i] + "=" + result[i] + ", ";
        }
        else if (fieldtypes[i] == "System.DateTime")
        {
            set += fields[i] + "='#" + System.DateTime.Now + "#', ";
        }
    }
    set = set.Substring(0, set.Length - 2);
    string sql11 = "UPDATE [Contacts] SET " + set + " WHERE pkContactID=" + cKey;
    OleDbCommand myCommand11 = new OleDbCommand(sql11, myConnection);
    myCommand11.ExecuteNonQuery();

Now this WORKED when I omitted the string and datetime conditions so that it only updated the int and boolean. So it has something to do with a syntax error when I try to update a field where the type is a string.


Then I heard that you have to use parameters when writing to an .mdb file, so I tried this:

        string sql11 = "UPDATE [Contacts] SET ";
        for (int i = 1; i < result.Count; i++)
        {
            sql11 += fields[i] + " = ?, ";
        }
        sql11 = sql11.Substring(0, sql11.Length - 2);
        sql11 += " WHERE pkContactID = " + cKey;
        using (myConnection)
        {
            using (OleDbCommand myCommand11 = new OleDbCommand(sql11, myConnection))
            {
                myCommand11.CommandType = CommandType.Text;
                for (int j = 1; j < result.Count; j++)
                {
                    if (fieldtypes[j] == "System.Int32")
                    {
                        myCommand11.Parameters.AddWithValue(fields[j], int.Parse(result[j]));
                    }
                    else if (fieldtypes[j] == "System.String")
                    {
                        myCommand11.Parameters.AddWithValue(fields[j], result[j]);
                    }
                    else if (fieldtypes[j] == "System.Boolean")
                    {
                        myCommand11.Parameters.AddWithValue(fields[j], Boolean.Parse(result[j]));
                    }
                    else if (fieldtypes[j] == "System.DateTime")
                    {
                        myCommand11.Parameters.AddWithValue(fields[j], DateTime.Now);
                    }
                }
                Console.WriteLine(sql11);
                myCommand11.ExecuteNonQuery();
            }
        }
    }

Which did not work either. I don’t think the ?’s are being replaced properly.

Anyway, please help me fix it so that I can update properly.

  • 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-06-17T15:54:08+00:00Added an answer on June 17, 2026 at 3:54 pm

    Instead of having to mess around with the UPDATE query string for Access, which is easily prone to syntax errors, I just created a DataTable object and SELECTed the row I wanted to UPDATE. I then updated the table via an array of the elements that I wanted to change, then updated the table back to the server using an adapter. This worked out well without me worrying about the syntax! 🙂

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
I have tried this example http://www.bennadel.com/blog/1056-ColdFusion-CFPOP-My-First-Look.htm , but it retrieve emails from POP server.
This is the first Python script I've tried to create. I'm reading a xml
I tried to load my Array s like this, but it loads just first
this is my first time asking a question here. I tried to be well
First of all, sorry if this isn't an appropriate question for StackOverflow. I've tried
I had implement this push notification . I tried with push first message, it
I find myself using a lot of nested maps, e.g a Map[Int, Map[String, Set[String]]],
I have a DataGrid like this: class SearchFile { public string path { set;
I have tried multiple ways to create this zip file in Java/Groovy. The first

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.