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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:18:07+00:00 2026-06-09T12:18:07+00:00

I used Extract Method on this code because there were multiples of this code,

  • 0

I used Extract Method on this code because there were multiples of this code, and here is what it became:

private void InsertStatement(string table, string table2, TestURLGUI4.Form1 form, SQLiteConnection sql_con, ref int dbID, ref int dbID2, Chrome chrome, int max)
{
    try
    {
        List<int> dbIDs = new List<int>();
        using (SQLiteTransaction mytransaction = sql_con.BeginTransaction())
        {
            using (SQLiteCommand mycommand = new SQLiteCommand(sql_con))
            {
                mycommand.CommandText = "insert or ignore into " + table + " (id, url, title, visit_count, frecency, last_visit_date) values (@dbID,@url,@title,@visit,@frecency,@time)";

                for (var count2 = 0; count2 < chrome.URLs.Count; count2++)
                {
                    URL u = chrome.URLs[count2];
                    mycommand.Parameters.Add(new SQLiteParameter("@dbID", dbID));
                    mycommand.Parameters.Add(new SQLiteParameter("@url", u.url));
                    mycommand.Parameters.Add(new SQLiteParameter("@title", u.title));
                    mycommand.Parameters.Add(new SQLiteParameter("@visit", u.frequency));
                    mycommand.Parameters.Add(new SQLiteParameter("@time", ToPRTime(u.visited)));
                    mycommand.Parameters.Add(new SQLiteParameter("@frecency", ToFrecency(u.frequency)));
                    mycommand.ExecuteNonQuery();
                    dbIDs.Add(dbID);
                    dbID++;
                    form.label1.Text = count2 + "/" + max;
                    Application.DoEvents();
                }

            }
            mytransaction.Commit();
        }
        using (SQLiteTransaction mytransaction = sql_con.BeginTransaction())
        {
            using (SQLiteCommand mycommand = new SQLiteCommand(sql_con))
            {
                mycommand.CommandText = "insert or ignore into " + table2 + " (id, from_visit, place_id, visit_date, visit_type, session) values (@dbID2,2,@dbID,@time,1, 0)";

                for (var count2 = 0; count2 < chrome.URLs.Count; count2++)
                {
                    URL u = chrome.URLs[count2];
                    mycommand.Parameters.Add(new SQLiteParameter("@dbID2", dbID2));
                    mycommand.Parameters.Add(new SQLiteParameter("@dbID", dbIDs[count2]));
                    mycommand.Parameters.Add(new SQLiteParameter("@time", ToPRTime(u.visited)));
                    mycommand.ExecuteNonQuery();
                    dbID2++;
                    form.label1.Text = count2 + "/" + max;
                    Application.DoEvents();
                }

            }
            mytransaction.Commit();
        }
    }
    catch
    {
        throw;
    }
}

The only problem is, instead of the Chrome type parameter, I have created multiple instances of different classes, and I need to pass each one, for example, I have

IE ie = new IE();
Firefox firefox = new Firefox();

etc. Now, how can I modify my parameter so that instead of Chrome, I can pass Chrome, Firefox, IE, etc. all in the same parameter, one at a time?

  • 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-09T12:18:09+00:00Added an answer on June 9, 2026 at 12:18 pm

    All your types are browsers, which means that you can (and should) refactor your code so that they all derive from one shared Browser class, if it’s not already like this. Once you do this, you can polymorphically change your method:

    private void InsertStatement(string table, string table2, TestURLGUI4.Form1 form, SQLiteConnection sql_con, ref int dbID, ref int dbID2, Browser browser, int max)
    

    If you are unwilling to do this then the only other solution I can think of is overloading the method.

    This article supplies information about inheritance in C#. Basically, what you do is:

    class Browser
    {
    }
    
    class IE : Browser
    {
    }
    

    You can then still initialize IE like this:

    IE ie = new IE();
    

    But you can also initialize it polymorphically like this:

     Browser ie = new IE();
    

    If you derive more classes from Browser, such as Firefox, Chrome, etc. then you can treat them all as a single type, Browser, inside a method.

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

Sidebar

Related Questions

The Cassandra command-line utility sstablekeys can be used to extract all defined row keys
I need to extract pixel information and populate a QPixmap to be used in
Used code I found on SO to use the COM based Acrobat Reader to
I used Jquery to insert a variable to div. Please check my code. var
I am trying to extract all substrings in a string that is between the
So this is the code I have tried, in C#, which failed to give
I have developed a GUI that is used to extract some data from a
I have a query on this. Please look at the sample code below: UIButton
I want to use Extract And Override pattern in my code, the pattern is:
I have this code in the php file. it lists all the interests as

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.