none
Typed Dataset (1 table) get colums value in a row RRS feed

  • Question

  • Hi all

    I have a typed dataset (UI_DS) created by designer that fill e dataTable (Customers)

    UI_DT_Customers = UI_DS.Customers

    Now I have to transfer the value of column ("CustomerName") in row (Nrow) to a textbox

    How to do it without write the column name in a string ?

    I mean without writing something like that

    TxtCustomerName.Text = UI_DS.Customers.rows(nrow).Item("CustomersName")

    Thank You for help

    Monday, June 11, 2018 4:51 PM

Answers

  • Hi Karen

    I did this

    The Dataset created by  designer has name 'DataSetCustomers'

    The table dragged has name 'Customers'

    So I did this 

    Dim row As DataSetCustomers.CustomersRow = UI_DS.Customers.Rows(Nrow) TxtCustomersID.Text = row.CustomerID

    TxtCustmerName.Text = row.CustomerName


    Is it correct ?  It seems to works

    If it works then it's okay but you should really code with Option Strict On. If row.CustomerID is a number it should have ,Tostring

    e.g. bad first, good second.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Tuesday, June 12, 2018 12:24 PM
    Monday, June 11, 2018 6:37 PM
    Moderator

All replies

  • Usually a typed DataSet is generated via the IDE data source designer.

    Drop a table on a form to get access to the DataSet -> DataTable of class members. If I want to get at a specific row we can use lambda in one of two forms.

    Public Class Form1
        Private Sub CustomersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) _
            Handles CustomersBindingNavigatorSaveItem.Click
    
            Validate()
            CustomersBindingSource.EndEdit()
            TableAdapterManager.UpdateAll(Me.NorthWindAzure1DataSet)
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            CustomersTableAdapter.Fill(NorthWindAzure1DataSet.Customers)
    
            TextBox1.Text = NorthWindAzure1DataSet.
                Customers.
                FirstOrDefault(Function(cust) cust.CustomerIdentifier = 3).
                ContactName
    
            TextBox2.Text = CType(CustomersBindingSource.DataSource, NorthWindAzure1DataSet).
                Tables("Customers").
                AsEnumerable.
                FirstOrDefault(Function(row) row.Field(Of Integer)("CustomerIdentifier") = 3).
                Field(Of String)("ContactName")
        End Sub
    End Class
    

    In this version the last method gets by a specific row value in nRow variable.

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        CustomersTableAdapter.Fill(NorthWindAzure1DataSet.Customers)
    
        TextBox1.Text = NorthWindAzure1DataSet.
            Customers.
            FirstOrDefault(Function(cust) cust.CustomerIdentifier = 3).
            ContactName
    
        TextBox2.Text = CType(CustomersBindingSource.DataSource, NorthWindAzure1DataSet).
            Tables("Customers").
            AsEnumerable.
            FirstOrDefault(Function(row) row.Field(Of Integer)("CustomerIdentifier") = 3).
            Field(Of String)("ContactName")
    
    
        Dim nRow As Integer = 2
        TextBox3.Text = NorthWindAzure1DataSet.
            Customers.Item(nRow).ContactName
    
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, June 11, 2018 5:18 PM
    Moderator
  • Hi Karen

    I did this

    The Dataset created by  designer has name 'DataSetCustomers'

    The table dragged has name 'Customers'

    So I did this 

    Dim row As DataSetCustomers.CustomersRow = UI_DS.Customers.Rows(Nrow) TxtCustomersID.Text = row.CustomerID

    TxtCustmerName.Text = row.CustomerName


    Is it correct ?  It seems to works

    Monday, June 11, 2018 5:31 PM
  • Hi Karen

    I did this

    The Dataset created by  designer has name 'DataSetCustomers'

    The table dragged has name 'Customers'

    So I did this 

    Dim row As DataSetCustomers.CustomersRow = UI_DS.Customers.Rows(Nrow) TxtCustomersID.Text = row.CustomerID

    TxtCustmerName.Text = row.CustomerName


    Is it correct ?  It seems to works

    If it works then it's okay but you should really code with Option Strict On. If row.CustomerID is a number it should have ,Tostring

    e.g. bad first, good second.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Tuesday, June 12, 2018 12:24 PM
    Monday, June 11, 2018 6:37 PM
    Moderator