none
reterive row from dataset RRS feed

  • Question

  • hi

    I want to reterivefull row of DataSet by entering the code field(CUSTOMERDETAILS_CODE)

    i select this field to  datagridview

     Dim cmd As OleDbCommand = New OleDbCommand("SELECT CUSTOMERDETALIS_ID,CUSTOMERDETAILS_CODE,CUSTOMERDETALIS_NAME,CUSTOMERDETALIS_CREDIT,CUSTOMERDETALIS_DEBIT,CUSTOMERDETALIS_BLANCE FROM  CUSTOMERDETAILS_TB ORDER BY CUSTOMERDETALIS_ID", con) 
            DataAdapterm = New OleDbDataAdapter(cmd)
            DataSetDG.Clear()
            DataAdapterm.Fill(DataSetDG, "CUSTOMERDETAILS_TB")
            DATAG_CLIENONLIN.DataSource = DataSetDG
            DATAG_CLIENONLIN.DataMember = "CUSTOMERDETAILS_TB"

    i used this code to reterive but not work

     
                    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM CUSTOMERDETAILS_TB WHERE CUSTOMERDETALIS_SHOW =Yes", con)
                    con.Open()
                    DataAdapterm = New OleDbDataAdapter(cmd)
                    DataSetupdat.Clear()
                    DataAdapterm.Fill(DataSetupdat, "CUSTOMERDETAILS_TB")
                    If DataSetupdat.Tables(0).Rows.Count > 0 Then
                        TextBox1.Text = "" : TextBox2.Text = ""
                        Dim indx As Integer = (DATAG_CLIENONLIN.CurrentRow.Cells(1).Value)
    
                        TextBox1.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_ID").ToString
                        TextBox2.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETAILS_CODE").ToString
                        TextBox3.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_NAME").ToString
                        TextBox4.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_COMPANY").ToString
                        TextBox5.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_TELEPHON").ToString
                        TextBox6.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_NOTE").ToString
                        TextBox7.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_DATE").ToString
                        TextBox8.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_CREDIT").ToString
                        TextBox9.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_DEBIT").ToString
                        TextBox10.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(indx).Item("CUSTOMERDETALIS_BLANCE").ToString
    
    
    
                    Else
                        MsgBox("data not found") : Exit Sub
                    End If

    all filed




    • Edited by ahmeddc Monday, October 8, 2018 10:18 AM
    Monday, October 8, 2018 10:10 AM

Answers

  • very sorry

    I did not complete my question. I also want to review the data of other tables in the form of the CUSTOMERDETAILS_CODEfield for the data set OF ANOTHER TABLE  NOT CURRENT OW ONLY

    Well then the same logic works other than identifying the specific row. Here I'm still targetting the same table as before but this works just the same as targetting another table.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim contactName = "Thomas Hardy"
        Dim results = bsCustomers.Find("ContactName", contactName)
        If results > -1 Then
            Dim row = CType(bsCustomers.DataSource, DataTable).Rows(results)
            MessageBox.Show(row("CompanyName").ToString)
        Else
            MessageBox.Show("Not located")
        End If
    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

    • Marked as answer by ahmeddc Monday, October 8, 2018 3:16 PM
    Monday, October 8, 2018 2:37 PM
    Moderator

All replies

  • If you added a BindingSource then it's easy.

    Add this to the top of your form as a variable.

    Private _bsData As New BindingSource

    Use it to set the DataSource of the DataGridView

    _bsData.DataSource = DataSetDG.Tables(0)
    DATAG_CLIENONLIN.DataSource = DataSetDG

    Later when you want to get the current row cast Current to a DataRow. Access fields via Field(Of X)

    Dim Row As DataRow = CType(_bsData.Current, DataRowView).Row
    Dim Code = Row.Field(Of String)("CUSTOMERDETAILS_CODE")


    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, October 8, 2018 10:38 AM
    Moderator
  • Dim Code = Row.Field(Of String)("CUSTOMERDETAILS_CODE")

    Error    54    'Field' is not a member of 'System.Data.DataRow

    i used vb 2010 fremwork 3

    Monday, October 8, 2018 12:18 PM
  • Dim Code = Row.Field(Of String)("CUSTOMERDETAILS_CODE")

    Error    54    'Field' is not a member of 'System.Data.DataRow

    i used vb 2010 fremwork 3

    You really should upgrade but in the mean time.

    Dim Code = Row("CUSTOMERDETAILS_CODE").ToString()


    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, October 8, 2018 12:30 PM
    Moderator
  •   I want to clarify some points that I have 2 datasets

    One particular display of columns is specific to the Data  = GridDataSetDG
    And the second I store the whole table by them and I want to review the data of the row where the code is specified  =

    DataSetupdat

    The following code was used to review the entire row of dataset with customer code information
    He did not work with me

    Monday, October 8, 2018 12:55 PM

  •                     _bsData.DataSource = DataSetupdat.Tables(0)
                        'DATAG_CLIENONLIN.DataSource = DataSetupdat
                        Dim Row As DataRow = CType(_bsData.Current, DataRowView).Row
                        Dim Code = Row("CUSTOMERDETAILS_CODE").ToString()
                       
                        TextBox1.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(Code).Item("CUSTOMERDETALIS_ID").ToString
                        TextBox2.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(Code).Item("CUSTOMERDETAILS_CODE").ToString
                        TextBox3.Text = DataSetupdat.Tables("CUSTOMERDETAILS_TB").Rows(Code).Item("CUSTOMERDETALIS_NAME").ToString

    Monday, October 8, 2018 12:55 PM
  • First off two things 

    • Who is "he" in "He did not work with me"
    • When you say "did not work", be specific.

    What I gave you works if you follow what I provided. Here is an example where the DataGridView is load via a DataTable. Sure you are using a DataSet but you are working with one DataTable at a time so this will work with a DataSet by targetting the specific DataTable.

    So if you follow what I provided and it does not work the only thing I can say is to upload your project in a .ZIP file to Microsoft OneDrive (sign into OneDrive with the same password used for login to this forum), provide me a link and I will look at it. Other than that I have nothing else to offer.


    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, October 8, 2018 1:36 PM
    Moderator
  • very sorry

    I did not complete my question. I also want to review the data of other tables in the form of the CUSTOMERDETAILS_CODEfield for the data set OF ANOTHER TABLE  NOT CURRENT OW ONLY

    Monday, October 8, 2018 2:20 PM
  • very sorry

    I did not complete my question. I also want to review the data of other tables in the form of the CUSTOMERDETAILS_CODEfield for the data set OF ANOTHER TABLE  NOT CURRENT OW ONLY

    Well then the same logic works other than identifying the specific row. Here I'm still targetting the same table as before but this works just the same as targetting another table.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim contactName = "Thomas Hardy"
        Dim results = bsCustomers.Find("ContactName", contactName)
        If results > -1 Then
            Dim row = CType(bsCustomers.DataSource, DataTable).Rows(results)
            MessageBox.Show(row("CompanyName").ToString)
        Else
            MessageBox.Show("Not located")
        End If
    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

    • Marked as answer by ahmeddc Monday, October 8, 2018 3:16 PM
    Monday, October 8, 2018 2:37 PM
    Moderator