回 帖 发 新 帖 刷新版面

主题:宝宝.....帮忙!!!!

怎么从数据集dataset里面读出比如说帐号和密码的一行..
就是从两个textbox里面的数据比较...又怎么返回结果..

回复列表 (共2个回复)

沙发

Public Function GetDataFromDB(ByVal sqlstr As String) As DataSet
            objDataSet = New DataSet
            objDataSet.Clear()
            '实例化一个数据集对象
            Try
                objSqlConnection.Open()
                '打开数据库连接
                objDataAdpter = New SqlDataAdapter(sqlstr, objSqlConnection)
                '将数据库的数据映射到数据适配器
                objDataAdpter.Fill(objDataSet)
                '填充数据集的数据
                objSqlConnection.Close()
                '关闭数据连接,这一点很重要
            Catch
                MsgBox("错误号:" & Err.Number & "错误描述:" & Err.Description)
            End Try
            Return objDataSet
            objDataSet = Nothing
        End Function
'以上这段写在模块里

Public objDataSet As DataSet
Dim User As String
    Dim Password As String
    Dim sqlstr As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        User = Me.ComboBox1.Text.Trim
        Password = Me.TextBox1.Text.Trim
        sqlstr = "SELECT * FROM pass WHERE username= " & _
        "'" & User & "' AND password='" & Password & "'"
        Dim objDataRow As DataRow
        Try
            objDataRow = GetDataFromDB(sqlstr).Tables(0).Rows(0)
        Catch
            MsgBox("密码和账号不符,请重试,并检查该账号是否存在。", _
            MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "系统登录失败")
            Me.TextBox1.Text = ""
            Exit Sub
        End Try
        Dim ccpcmain As New ccpcmain
        Me.Hide()
        ccpcmain.ShowDialog()
        Me.Close()
    End Sub

对于这段代码,我也是看别人写的,然后自己用了。你回头改下就OK了

板凳

我也经搞定了。。。。。。不过谢啦。。

我来回复

您尚未登录,请登录后再回复。点此登录或注册