How do I pass data from a DataView to a Text Box?

DavidHannen
DavidHannen used Ask the Experts™
on
Help would be appreciated. I am programming in a new area here and am totally lost!!

I have a SQL Server Express Database and VB.Net 2008 (framework 3.5) application

I can conect to the database from VS  through a  login diaolg form (using SQL Server Authentication).  Once logged in I can open the main form and populate a 'Search' combo box with relevant values from the SQL server with a SQLConnection and a dataset.

Now I want to select a value in the combo box, hit a button and get the code to populate the fields on the (disconnected) form with the data related to the selected record in the combo based upon its ID

Hope that makes sense.

I want to open a dataset of database records for the current table and filter it with a dataview to the selected record in the combo box ()Based on ID), then populate the fields on the form from the the dataview.

But  cannot make it work.

The dataset works that populates the combo box

But the dataview fails

My rather verbose code is attached ??! :-)

Thanks







 
Sub sbLoadSelectedMemberRecord(ByVal MemberID As Integer)
        '==============================================================
        'Description:   Loads main form with a selected record
        'Author:        
        'Date:          28/01/2010
        'Revised By:    na
        'Revised Date:  na
        '==============================================================
        Dim SQLcnn As New clsConnectivity()
        Dim objCnn As SqlConnection = New SqlConnection(SQLcnn.cnn.ToString)
        Dim objDataAdapter As New SqlDataAdapter()
        Dim objMemDS As DataSet = New DataSet()
        Dim objMemDV As DataView

        objDataAdapter.SelectCommand = New SqlCommand
        objDataAdapter.SelectCommand.Connection = objCnn
        objDataAdapter.SelectCommand.CommandText = strMemberSQL 'SQL string representing required table fields in SQL Server DB
        objDataAdapter.SelectCommand.CommandType = CommandType.Text

        Try
            '---------------------------------
            'Create the dataset and data views
            objDataAdapter.Fill(objMemDS, "Member")
            objMemDV = New DataView(objMemDS.Tables("Member"))
            objMemDV.RowFilter = "MEMBER_ID = " & MemberID
            objDataAdapter = Nothing
        Catch ex As Exception
            '-----------------
            'Data load errors
            Dim errString As String = "[Error Number: " & Err.Number & "] - " & Err.Description & "{frmMember~Record Load}" & vbCrLf _
            & "Please review the Help Guide, Chapter Errors, section Combo Data Upload."
            MsgBox(errString, MsgBoxStyle.Information, "Unexpected System Error")
            Err.Clear()
            Exit Sub
        End Try

        '---------------------------------
        'Update form with dataview record
        'FirstNM.Text = Dataview(objMemDV).("MEMBER_ID")  'CANT GET FORM FIELD UPLOAD TO WORK HERE!!!!!




    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Try
FirstNM.Text = objMemDV(0)("MEMBER_ID").tostring  'CANT GET FORM FIELD UPLOAD TO WORK HERE!!!!!
Hi DavidHannen,

FirstNM.Text = Dataview(0).item("MEMBER_ID").ToString()

Author

Commented:
Thanks. I had spent ages on that

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial