Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. szotar.aspx.cs
  2.  
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.Configuration;
  11. using System.Data;
  12. using System.Data.SqlClient;
  13.  
  14. namespace WebApplication5
  15. {
  16. public partial class Szotar : System.Web.UI.Page
  17. {
  18.  
  19. SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["fordit"].ConnectionString);
  20. protected void Page_Load(object sender, EventArgs e)
  21. {
  22.  
  23. }
  24.  
  25. protected void TextBox1_TextChanged(object sender, EventArgs e)
  26. {
  27.  
  28. }
  29.  
  30. protected void Button1_Click(object sender, EventArgs e)
  31. {
  32. try
  33. {
  34. if (DropDownList1.SelectedValue == "Angol - Magyar")
  35. {
  36. con.Open();
  37. SqlCommand select = new SqlCommand("SELECT Magyar, Leiras FROM fordito WHERE Angol like @forditani;", con);
  38. select.Parameters.AddWithValue("@forditani", TextBox1.Text);
  39. SqlDataReader datar;
  40. datar = select.ExecuteReader();
  41. while (datar.Read())
  42. {
  43. Label4.Text = datar[0].ToString();
  44. Label5.Text = datar[1].ToString();
  45. }
  46. datar.Close();
  47. datar.Dispose();
  48. }
  49. else if (DropDownList1.SelectedValue == "Magyar - Angol")
  50. {
  51. con.Open();
  52. SqlCommand select = new SqlCommand("SELECT Angol, Leiras FROM fordito WHERE Magyar like @forditani;", con);
  53. select.Parameters.AddWithValue("@forditani", TextBox1.Text);
  54. SqlDataReader datar;
  55. datar = select.ExecuteReader();
  56. while (datar.Read())
  57. {
  58. Label4.Text = datar[0].ToString();
  59. Label5.Text = datar[1].ToString();
  60. }
  61. datar.Close();
  62. datar.Dispose();
  63. }
  64. }
  65. catch (Exception)
  66. {
  67. Label6.Text = "Hiba!";
  68. }
  69. finally
  70. {
  71. con.Close();
  72. }
  73. }
  74. }
  75. }
  76.  
  77.  
  78. lap.aspx.cs [bevitel]
  79.  
  80.  
  81. using System;
  82. using System.Collections.Generic;
  83. using System.Linq;
  84. using System.Web;
  85. using System.Web.UI;
  86. using System.Web.UI.WebControls;
  87. using System.Web.Configuration;
  88. using System.Data;
  89. using System.Data.SqlClient;
  90.  
  91. namespace WebApplication5
  92. {
  93. public partial class lap : System.Web.UI.Page
  94. {
  95. SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["fordit"].ConnectionString);
  96. protected void Page_Load(object sender, EventArgs e)
  97. {
  98.  
  99. }
  100.  
  101. protected void Button1_Click(object sender, EventArgs e)
  102. {
  103. SqlCommand insert = new SqlCommand("INSERT INTO szavak VALUES(@Angol,@Magyar,@Leiras);", con);
  104. insert.Parameters.AddWithValue("@Angol", TextBox1.Text);
  105. insert.Parameters.AddWithValue("@Magyar", TextBox2.Text);
  106. insert.Parameters.AddWithValue("@Leiras", TextBox3.Text);
  107. try
  108. {
  109. con.Open();
  110. if (insert.ExecuteNonQuery() < 0)
  111. {
  112. Label4.Text = "Sikertelen adatfeltoltes!";
  113. }
  114. }
  115. catch (Exception)
  116. { }
  117. finally
  118. {
  119. con.Close();
  120. }
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement