Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. SqlConnection x = new SqlConnection(WebConfigurationManager.ConnectionStrings["fordito"].ConnectionString);
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4.  
  5. }
  6.  
  7. protected void Button1_Click(object sender, EventArgs e)
  8. {
  9. if (DropDownList1.Text == "Angolról")
  10. {
  11. string forditas = "SELECT Srpski,Opis FROM Szavak WHERE Engleski = @szavak";
  12. SqlCommand forditasstring = new SqlCommand(forditas, x);
  13. forditasstring.Parameters.AddWithValue("@szavak", TextBox1.Text);
  14. try
  15. {
  16. x.Open();
  17. SqlDataReader dr = forditasstring.ExecuteReader();
  18. while (dr.Read())
  19. {
  20. TextBox2.Text = dr[0].ToString();
  21. TextBox3.Text = dr[1].ToString();
  22. }
  23. dr.Close();
  24. }
  25. catch (Exception hiba)
  26. {
  27. Label4.Text = hiba.ToString();
  28. }
  29. finally
  30. {
  31. x.Close();
  32. }
  33. }
  34. else if (DropDownList1.Text == "Szerbről")
  35. {
  36. string forditas = "SELECT Engleski,Opis FROM Szavak WHERE Srpski = @szavak";
  37. SqlCommand forditasstring = new SqlCommand(forditas, x);
  38. forditasstring.Parameters.AddWithValue("@szavak", TextBox1.Text);
  39. try
  40. {
  41. x.Open();
  42. SqlDataReader dr = forditasstring.ExecuteReader();
  43. while (dr.Read())
  44. {
  45. TextBox2.Text = dr[0].ToString();
  46. TextBox3.Text = dr[1].ToString();
  47. }
  48. dr.Close();
  49. }
  50. catch (Exception hiba)
  51. {
  52. Label4.Text = hiba.ToString();
  53. }
  54. finally
  55. {
  56. x.Close();
  57. }
  58. }
  59.  
  60.  
  61.  
  62. SqlConnection x = new SqlConnection(WebConfigurationManager.ConnectionStrings["fordito"].ConnectionString);
  63. protected void Page_Load(object sender, EventArgs e)
  64. {
  65.  
  66. }
  67.  
  68. protected void Button1_Click(object sender, EventArgs e)
  69. {
  70. try
  71. {
  72. string insert = "INSERT INTO Szavak VALUES(@engleski,@srpski,@opis)";
  73. SqlCommand insertstring = new SqlCommand(insert, x);
  74. insertstring.Parameters.AddWithValue("@srpski", TextBox1.Text);
  75. insertstring.Parameters.AddWithValue("@engleski", TextBox2.Text);
  76. insertstring.Parameters.AddWithValue("@opis", TextBox3.Text);
  77.  
  78. x.Open();
  79. if (insertstring.ExecuteNonQuery() > 0)
  80. {
  81. Label4.Text = "Sikerült";
  82. }
  83.  
  84. else
  85. {
  86. Label4.Text = "Nem sikerült";
  87. }
  88. }
  89.  
  90. catch (Exception c)
  91. {
  92.  
  93. Label4.Text = c.ToString();
  94. }
  95. finally
  96. {
  97.  
  98. x.Close();
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement