Перевести код с C# - Visual Basic .NET

Узнай цену своей работы

Формулировка задачи:

Здравствуйте! Пишу программуи не могу разобраться как переделать этот код под Visual Basic Я конечно понимаю,что они похожи,но все же.
Листинг программы
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. int count = 0;
  4. using (SqlConnection connection = new SqlConnection(@"Data Source=prodenis\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db_APM.mdf;Integrated Security=True;user Instance=True"))
  5. using (SqlCommand command = new SqlCommand("select * from [user] where user=user and password=password", connection))
  6. {
  7. command.Parameters.AddWithValue("user", textBox1.Text);
  8. command.Parameters.AddWithValue("password", textBox2.Text);
  9. connection.Open();
  10. using (SqlDataReader reader = command.ExecuteReader())
  11. {
  12. while (reader.Read())
  13. count += 1;
  14. }
  15. connection.Close();
  16. }
  17. if (count == 0)
  18. {
  19. MessageBox.Show("Пароль неверен!");
  20. return;
  21. }
  22. this.Hide();
  23. APM frm2 = new APM();
  24. frm2.Show();
  25. }
  26. }
  27. }

Решение задачи: «Перевести код с C#»

textual
Листинг программы
  1. Private Sub button2_Click(sender As Object, e As EventArgs)
  2.     Dim count As Integer = 0
  3.     Using connection As New SqlConnection("Data Source=prodenis\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db_APM.mdf;Integrated Security=True;user Instance=True")
  4.         Using command As New SqlCommand("select * from [user] where user=user and password=password", connection)
  5.             command.Parameters.AddWithValue("user", textBox1.Text)
  6.             command.Parameters.AddWithValue("password", textBox2.Text)
  7.             connection.Open()
  8.             Using reader As SqlDataReader = command.ExecuteReader()
  9.                 While reader.Read()
  10.                     count += 1
  11.                 End While
  12.             End Using
  13.             connection.Close()
  14.         End Using
  15.         If count = 0 Then
  16.             MessageBox.Show("Пароль неверен!")
  17.             Return
  18.         End If
  19.         Me.Hide()
  20.         Dim frm2 As New APM()
  21.         frm2.Show()
  22.     End Using
  23. End Sub

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

6   голосов , оценка 4 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут