public void updateclientdata(clientdata cdd) { SqlConnection C = new SqlConnection(ConnectionString); SqlCommand modclient = new SqlCommand(@"UPDATE [dbo].[clientdata] SET [ISP] = @pisp ,[ORG] = @porg ,[ASN] = @pasn WHERE [playerId] = @pid", C); SqlParameter p1 = new SqlParameter("@pisp", System.Data.SqlDbType.NVarChar, 50); p1.Value = cdd._isp; modclient.Parameters.Add(p1); SqlParameter p2 = new SqlParameter("@porg", System.Data.SqlDbType.NVarChar, 50); p2.Value = cdd._org; modclient.Parameters.Add(p2); SqlParameter p3 = new SqlParameter("@pasn", System.Data.SqlDbType.NVarChar, 50); p3.Value = cdd._asn; modclient.Parameters.Add(p3); SqlParameter p4 = new SqlParameter("@pid", System.Data.SqlDbType.Int); p4.Value = cdd.playerId; string _IDD = cdd.playerId.ToString(); modclient.Parameters.Add(p4); C.Open(); modclient.ExecuteNonQuery(); C.Close(); Console.WriteLine("Player-ID "+_IDD+" updated."); }
static void Main(string[] args) { DataTable table = new DataTable(); SqlConnection C = new SqlConnection(ConnectionString); C.Open(); SqlDataAdapter a = new SqlDataAdapter("select playerId, lastAddress from [dbo].[hlstats_players]", C); a.Fill(table); C.Close(); List<clientdata> list = new List<clientdata>(); list = (from DataRow dr in table.Rows select new clientdata() { playerId=Convert.ToInt32( dr["playerId"]), _ip = dr["lastAddress"].ToString() }).ToList(); // List<clientdata> dblist = new List<clientdata>(); for (int i = 0; i < list.Count; i++) { string url = "http://ip-api.com/xml/" + list[i]._ip; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; XmlDocument doc = new XmlDocument(); doc.Load(url); XmlNodeList nodes = doc.DocumentElement.SelectNodes("/query"); foreach (XmlNode node in nodes) { if(node.SelectSingleNode("status").InnerText.Contains("success")) { clientdata _cl = new clientdata(); _cl.playerId = list[i].playerId; _cl._ip = list[i]._ip; _cl._isp = node.SelectSingleNode("isp").InnerText; _cl._org = node.SelectSingleNode("org").InnerText; _cl._asn = node.SelectSingleNode("as").InnerText; Thread.Sleep(300); Program ps = new Program(); ps.updateclientdata(_cl); } } } }