1 Replies - 908 Views - Last Post: 21 March 2012 - 08:09 AM Rate Topic: -----

#1 kimsnap  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-March 12

Displaying data from database through passed value from another form

Posted 20 March 2012 - 05:34 AM

hi. I am trying to display FirstName value from my database to a label in my form but it always gets an error.

InfoDb is my Access Database. It contains the ff columns: UserName, Password, and FirstName.
_AccName is the passed text in UNameTB-textbox in my login form which pertains to the UserName in my database.

AccountName is a label in my useraccount form. When successfully logged in, it must be changed to the corresponding FirstName value in my database that matched the Username given by the passed value.

but my coding is obviously wrong since it does not. im getting this error after successfully logging in: No given value for one or more required parameters.

Heres the code for passing value from login code
'passed details starts here
                Dim Obj As New UserAccount
                Obj.PassedText = UNameTB.Text
'end


My coding for useraccount form:
Public Class UserAccount
    Private _AccName As String
    Private mstrConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                 "Data Source=" & Application.StartupPath & "\InfoDb.accdb;"


    Public Property [PassedText]() As String
        Get
            Return _AccName
        End Get
        Set(ByVal Value As String)
            _AccName = Value
            Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(mstrConn)
            Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT FirstName FROM DB where UserName= " & _AccName & " ", conn)
            Dim getInfo As OleDb.OleDbDataReader
            conn.Open()

            getInfo = cmd.ExecuteReader
            While getInfo.Read
                AccountName.Text = getInfo.ToString()
            End While
            conn.Close()

        End Set
    End Property
    End Sub

End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Displaying data from database through passed value from another form

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Displaying data from database through passed value from another form

Posted 21 March 2012 - 08:09 AM

Have you try with data adapter?
Public Class UserAccount
    Private _AccName As String
    Private mstrConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                 "Data Source=" & Application.StartupPath & "\InfoDb.accdb;"


    Public Property [PassedText]() As String
        Get
            Return _AccName
        End Get
        Set(ByVal Value As String)
            _AccName = Value
            Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(mstrConn)
            conn.Open()
            Dim iDa As New OleDb.OleDbDataAdapter("SELECT FirstName FROM DB where UserName= " & _AccName & " ", conn)
            Dim tbl As New DataTable
            iDa.Fill(tbl)
            AccountName.Text = tbl.Rows(0).Item(0).ToString()
            conn.Close()
            iDa.Dispose()
            tbl.Dispose()
        End Set
    End Property
    End Sub

End Class



InfoDb is your Access Database, and what is the name of the Table? is 'DB' right name?
SELECT FirstName FROM DB where UserName= ...

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1