formulaire de connexion VB (wampserver)
Bonjour,
Jai essayé de créer un formulaire de connexion pour mon application créée en VB mais ça ne marche pas. Je n'ai pas pu me connecter à ma base de données sur wampserver. J'ai obtenu ce message:"Connexion au serveur indisponible."
Merci de m'aider à corriger ce code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim conn As New SqlConnection("SERVER=localhost; uid =root; PASSWORD =; DATABASE =center_vb")
Try
conn.Open()
Catch myerror As SqlException
MsgBox("Connexion au serveur indisponible.", vbCritical)
Exit Sub
End Try
Dim mysqladapter As New SqlDataAdapter
Dim sqlquery = "SELECT * FROM users WHERE login='" & TextBox1.Text & " 'AND password='" & TextBox2.Text & "';"
Dim mycommand As New SqlCommand
mycommand.Connection = conn
mycommand.CommandText = sqlquery
mysqladapter.SelectCommand = mycommand
Dim mydata As SqlDataReader
mydata = mycommand.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("Connexion refusée.", vbCritical)
Else
Form2.Show()
End If
End Sub
End Class |