运行时, adapter.Fill(mydataset, "CmbPurview.Text")这句有问题,问题是“在调用“Fill”前,SelectCommand 属性尚未初始化”。
Private Sub BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
Me.Text = "正在验证...."
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
Dim comstr As String
Dim SqlConn As New SqlConnection("data source=.\sqlexpress;initial catalog=信息追踪系统;Persist Security Info=true;Integrated Security=SSPI;")
Dim mydataset As New DataSet()
comstr = "select 密码 from & CmbPurview.Text & where 用户名 = '" & Trim(TxtUserName.Text) & "'"
mydataset.Clear()
Dim adapter As New SqlDataAdapter
adapter.Fill(mydataset, "CmbPurview.Text")
If mydataset.Tables("CmbPurview.Text").Rows(0).Item(0) = Trim(TxtPassword.Text) Then
UserInf(0) = Trim(TxtUserName.Text)
UserInf(1) = CmbPurview.Text
If CmbPurview.Text <> "管理员" Then
With ob_interface
.BtGoods.Visible = False
.BtSaleHistory.Visible = False
End With
End If
ob_interface.Show()
Me.Hide()
Else
MsgBox("密码错误!")
TxtPassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow
TxtPassword.Focus()
End If
------解决方案--------------------
Dim adapter As New SqlDataAdapter(comstr ,SqlConn )