我是一个新的学习视觉工作室。我得到一个错误
连接属性尚未初始化
这是我的代码:
Imports System.Data.SqlClient
Public Class Form1
Dim con As SqlConnection
Dim cm As SqlCommand
Dim dr As SqlDataReader
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
TextBox2.PasswordChar = ""
Else
TextBox2.PasswordChar = "•"
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.MaxLength = 50
TextBox2.PasswordChar = "•"
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("pls fill the data", MsgBoxStyle.Information)
Exit Sub
Else
Call Koneksi()
cm = New SqlCommand("select*from login where username='" & TextBox1.Text & "'and password" & TextBox2.Text & "'", con)
cm.Connection = con
dr = cm.ExecuteReader
dr.Read()
last.Show()
Me.Close()
If dr.HasRows Then
MsgBox("succes", MsgBoxStyle.Information, "information")
Else
MsgBox("wrong password/username", MsgBoxStyle.Critical)
TextBox1.Clear()
TextBox2.Clear()
End If
End If
End Sub
End Class