Jebavam se celo popodne s ovim.
Pokušavam da se povežem s bazom.
Dva polja na formi, dva polja u bazi.
Private Sub btnPrijava_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrijava.Click
Dim connection As New SqlClient.SqlConnection
Dim command As New SqlClient.SqlCommand
Dim adaptor As New SqlClient.SqlDataAdapter
Dim dataset As New DataSet
connection.ConnectionString = ("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Baza.mdf;Integrated Security=True;User Instance=True")
command.CommandText = "SELECT * FROM [Korisnici] WHERE KorisnickoIme='" & txtKorisnicko.Text & "' AND Lozinka='" & txtLozinka.Text & "';"
connection.Open()
command.Connection = connection
adaptor.SelectCommand = command
adaptor.Fill(dataset, "0")
Dim count = dataset.Tables(0).Rows.Count
If count > 0 Then
MsgBox("Login Successfull", MsgBoxStyle.Information, "Login Passed")
Else
MsgBox("Invalid Account", MsgBoxStyle.Critical, "Login Failed")
txtKorisnicko.Clear()
txtLozinka.Clear()
End If
End Sub
Prvo sam mislio da je problem u kodu, ali onda sam video da onaj znak pored baze da je konektovana, nestane kada Build-ujem programče.
Zna li neko u čemu je problem? Kako da osiguram sigurnu konekciju sa bazom?
Da pojasnim, možda sam pogrešio i u toku kreiranju same baze.
Znači, dodao sam novi Item, Service-based Database, kreirao tabelu, a dodao New Data Source.
|