我是一個初學者程序員。C#。連接到數據集,獲取UserID並搜索網頁
我寫了下面的代碼必須執行以下步驟:
1連接到我的數據集有兩個字段:用戶ID,的TrackID(2916場) 2逐行讀取數據集線,把用戶ID每個記錄到一個url(而不是)。 3 - 通過Url搜索 4 - 如果發現與UserId相關的TrackId,則將計數器加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 test2
{
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);
int UserID=0,TrackID=0;
int counter=0;
foreach(DataRow row in dt.Rows)
{
string url = "http://abcd/<userid>?groups=<userid>";
var test = url.Replace("<userid>", Convert.ToString(row.UserID));
System.Diagnostics.Process.Start(url);
string client = (new WebClient()).DownloadString("http://abcd/UserID?groups=UserID");
if (client.Contains(Convert.ToString(TrackID)))
{
counter++;
}
int ave = counter/2916;
MessageBox.Show("Average" + counter);
}
conn.Close();
}
}
}
''我寫錯了嗎?''爲什麼你不試試看?如果你嘗試了什麼,你會得到什麼錯誤,異常,未展現的結果? –