Results 1 to 8 of 8

Thread: errors with System.Data.Datarow

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Question errors with System.Data.Datarow

    Hi, this is my code:

    Dim datarow1 as DataRow

    datarow1 = DataSchema1.Clientes.NewRow()
    datarow1 = DataSchema1.Clientes.Select("IdCliente=IdClienLabel.Text)
    NombreCliente.Text = datarow1("Nombre").ToString

    And the DataSchem....select... line gets underlined in blue and it says that "a value of type '1-matrix dimensional of System.Data.DataRow' can't be converted to '2' "

    Any clue? Thanks heaps!!

  2. #2
    Addicted Member
    Join Date
    Apr 2004
    Location
    Lagos, Nigeria
    Posts
    215
    The Select() method of the datatable returns a 1-dimensional array of type DataRow. The following example should give you a guide.

    VB Code:
    1. Dim rows() As DataRow
    2. rows = DataSchema1.Clientes.Select("IdCliente = IdClienLabel.Text")
    3.  
    4. If (Not rows Is Nothing) Then
    5.     Text1.Text = rows(0).Item("Nombre").ToString
    6. End If

  3. #3
    Addicted Member
    Join Date
    Apr 2004
    Location
    Lagos, Nigeria
    Posts
    215
    The Select() method of the datatable returns a 1-dimensional array of type DataRow. The following example should give you a guide.

    VB Code:
    1. Dim rows() As DataRow
    2. rows = DataSchema1.Clientes.Select("IdCliente = IdClienLabel.Text")
    3.  
    4. If (Not rows Is Nothing) Then
    5.     Text1.Text = rows(0).Item("Nombre").ToString
    6. End If

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    In case you post the same thread twice, just edit one of them and mark as [Please Delete]. It confuses us simple folk.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70
    Hey thanks for your help,

    I'm still getting an error, now what if get is from the line that goes ...rows(0)... it says the index is out of matrix range.

    What I'm trying to do is to select rows of data applying a filter from my dataset, I thought just defining a variable as datarow and having it contain the results from select() would be enough but I guess it isn't.

    Thanks again.

  6. #6
    Addicted Member
    Join Date
    Apr 2004
    Location
    Lagos, Nigeria
    Posts
    215
    If the number of elements in the array [datarow array] is less than one, it should return nothing -- I think.

    May be you should try
    VB Code:
    1. If (rows.Length > 0) Then
    2.     Text1.Text = rows(0).Item("Nombre").ToString
    3. End If

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70
    Ok yeah, that was the problem the select() method was giving me no results. But now I've tried setting it this way:

    Dataschema1.Clientes.Select("IdCliente=4") and it still gives me no results back. And I know there is a Client whos ID is 4. In the table IdCliente is defined as integer.

    How come it isn't retrieving the data correctly.?

    Thanks lots!!!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70
    Ok, got it! It is because I had to do Dataschema1.ReadXml()

    Do I have to read the xml everytime I run a form? Can't I do it at the beginning of the application once for all?

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width