Advertisement
thebys

Untitled

May 8th, 2011
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. //kde se bere string okres:
  2.  public static void Tfilllevel3(string soubor)
  3.         {
  4.         HtmlAgilityPack.HtmlDocument dokument = new HtmlAgilityPack.HtmlDocument();
  5.         dokument.Load(soubor, System.Text.Encoding.GetEncoding(28592));
  6.     //načte dokument se správným kódováním (volby.cz, diakritika)
  7.         //zjištění distric ID - zjistíme jméno okresu a provnáme s DB
  8.         HtmlNode h3 = dokument.DocumentNode.SelectSingleNode("//h3[2]");
  9.         //odstraníme "Okres: " abychom dostali jen jméno okresu
  10.         string okres = h3.InnerText.ToString();
  11.         okres = okres.Remove(0, 8);
  12.         //budeme zjišťovat districtid
  13.         int rid = dbo.getdistrictid(okres);
  14.         }
  15.  
  16.  
  17.  
  18.         public static int getdistrictid(string okres)
  19.         {
  20.             string dname = okres;
  21.             string cstring = Properties.Settings.Default.volbydbConnectionString;
  22.             using (SqlConnection sqlpripojeni = new SqlConnection(cstring))
  23.             using (SqlCommand getrid = new SqlCommand("SELECT DistrictId FROM Districts WHERE Name= @Districtname", sqlpripojeni))
  24.             {
  25.                 getrid.Parameters.Add(new SqlParameter("@Districtname", SqlDbType.NVarChar, dname.Length)).Value = dname;
  26.                 sqlpripojeni.Open();
  27.                 return Convert.ToInt32(getrid.ExecuteScalar());
  28.             }
  29.         }
  30.  
  31. //Stale vraci 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement