Question

I am trying to write a code with C# which read an access database that has two fields (User ID, Track ID) line by line and set the each userID in the following url (replace the tag with userID):

http://abcdef.comghijklmnopqrstuvwxyz<userid>?groups=<userid>

and search through the data which shows on webpage(the data is in JSON format). if the Track ID which is in the same record of User ID shows, the counter increase 1.

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Net;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\hidden.accdb";
            conn.Open();
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = conn;
            cmd.CommandText = "Select * from hidden.accdb";
            DataTable dt = new DataTable();
            //To read data from dataset
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = cmd;
            //Store the UserID
            adapter.Fill(dt);
            conn.Close();
        }

        private void btn_run_Click(object sender, EventArgs e)
        {

            int UserID;
            int TrackID;
            int counter=0;
            for (int ID = 1; ID <= 2916; ID++)
            {

                string url = "http://abcdef.com/ghijklmnopqrstuvwxyz<userid>?groups=<userid>";
                string test = test.Replace("i", Convert.ToString(UserID));
                System.Diagnostics.Process.Start(url);
                string client = (new WebClient()).DownloadString("http://abcdef.com/ghijklmnopqrstuvwxyz<userid>?groups=<userid>");
                if (client.Contains(Convert.ToString(TrackID)))
                {
                    counter++;
                }
            }
int ave= counter/2916;
}
}
}
Was it helpful?

Solution

you need to do

var test = url.Replace("<userid>",Convert.ToString(UserID));

Is that not what your after?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top