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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:15:45+00:00 2026-05-15T17:15:45+00:00

I have an object, say a note, whose parameters I want to save in

  • 0

I have an object, say a note, whose parameters I want to save in a table(content, size, width, height, etc).
With having the sql string updateNotes:

UPDATE NOTES 
SET 
    CONTENT=@content, 
    POSX=@posX, 
    POSY=@posY,
    COLOR=@color,
    ORIENTATION=@orientation,
    HEIGHT=@height,
    WIDTH=@width,
    AUTHOR=@autho 
WHERE SESSION =@sid

    public void save()
    {
        SQLiteConnection conn = new SQLiteConnection(connectionString);

        foreach (Note note in notes)
        {
            using (SQLiteCommand comm = new SQLiteCommand(updateNotes, conn))
            {
                comm.Parameters.AddWithValue("@content", note.getNoteItemContent());
                comm.Parameters.AddWithValue("@posX", note.getSvi().Center.X);
                comm.Parameters.AddWithValue("@posY", note.getSvi().Center.Y);
                comm.Parameters.AddWithValue("@sid", sid);
                comm.Parameters.AddWithValue("@color", note.getColor());
                comm.Parameters.AddWithValue("@orientation", note.getSvi().Orientation);
                comm.Parameters.AddWithValue("@height", note.getSvi().ActualHeight);
                comm.Parameters.AddWithValue("@width", note.getSvi().ActualWidth);
                comm.Parameters.AddWithValue("@author", note.getAuthor());

                try
                {
                    conn.Open();
                    comm.ExecuteNonQuery();
                    comm.Parameters.Clear();
                }
                catch (Exception e) { Microsoft.Surface.UserNotifications.RequestNotification("Database error", "Could not write to the database:" + e.Message); }
                finally
                {
                    if (conn != null) { conn.Close(); }
                    listLoaded = false;
                }
            }
        }
    }

The method above does indeed update the rows in the table but with one value for all the rows that result from the query.

As a solution I thought of reading the note id first and then iterate (i++), but given that some notes(represented as rows in the table) may be deleted, the id will not necessarily follow a consecutive numbering.

Another solution was to query the database for all the rows(notes) for the given session(sid) and store their id in an array and the update the notes whose id can be found in the array.

Do you know of any other better optimised solution? Or do you reckon I should use the array for storing the id’s of the rows to be updated and the apply the query.

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-15T17:15:46+00:00Added an answer on May 15, 2026 at 5:15 pm

    We seem to have resolved this in the question’s comments but just to be clear on the answer (and hopefully give you something to accept), here is a summary:

    When creating note objects, the data constituting those notes is selected from the database. As well as selecting outward facing data such as the note colour and content, we also select the primary key of each note and store this as a property of the note object.

    Now, when a note object is updated, you can include its id in the where clause for the corresponding update statement and hence only update the one row corresponding to the modified note.

    Glad I could provide some “enlightenment” — as you put it.

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

Sidebar

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.