为什么总说mycommand.ExecuteNonQuery()这句错误,问题是“ExecuteNonQuery: Connection 属性尚未初始化”。
If CmbPurview.Text = "一般用户" Then
If TxtPassword.Text = TxtConfirmPassword.Text Then
Dim SqlConn As New SqlConnection("data source=.\sqlexpress;initial catalog=信息追踪系统;Persist Security Info=true;user id=sa;password=")
SqlConn.Open()
Dim comstr As String = "insert into " & CmbPurview.Text & " values('" & TxtUserName.Text & "','" & CChar(TxtPassword.Text) & "')"
Dim mycommand As New SqlCommand(comstr, SqlConn)
mycommand.ExecuteNonQuery()
SqlConn.Close()
MsgBox("添加成功!")
Else
MsgBox("两次密码输入不相同,请重新输入!")
TxtPassword.Text = ""
TxtConfirmPassword.Text = ""
TxtPassword.Focus()
End If
------解决方案--------------------
Dim mycommand As New SqlCommand(comstr, SqlConn);
mycommand.connetion = SqlConn;
------解决方案--------------------
你的数据库没有开启sa登陆,默认是不开放的,网上有很详细的说明,去查查