我的代码出了什么问题?当我运行程序时,它说ExecuteNonQuery:Connection属性尚未初始化。"谢谢。请帮帮我。
Private Sub btnentidel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnentidel.Click
conn.Open()
Dim cmd As New SqlCommand
cmd.CommandText = String.Format("DELETE FROM tblentityreg WHERE [Registered Business Trade Name] = @p1")
cmd.Parameters.AddWithValue("@p1", txtregplace.Text)
Dim affectedRows = cmd.ExecuteNonQuery
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim cmd1 As SqlCommand = conn.CreateCommand
cmd1.CommandText = "SELECT * FROM tblentityreg"
Dim dtentity As New DataTable
dtentity.Load(dr)
DataGridView1.DataSource = dtentity
dr.Close()
If affectedRows > 0 Then
MsgBox("Succesfully Deleted the Record!")
Else
MsgBox("Failed!")
End If
conn.Close()
txtentisearch.Text = ""
End Sub