Results 1 to 9 of 9

Thread: Trying again!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Resolved Trying again!!

    Hi everyone, I posted this question but got no answer, can somebody help me out!!??

    I'm trying to update my xml database.

    I have a table called Clients (columns: Id, Name,..., Erased), and I'm trying to modify the column Erased from False to True (yes it is a boolean column).

    I only want to modify the dataset and then run dataset.writexml, there is no sql database or any other external database.

    I know there is a command dataset.select() for selecting rows but isn't there anything for updating??? (changing one value of one column of one row)

    Erasing a column and then adding the changed one won't work because the database won't let me because there are table relations and erasing one would be incoherent. And adding the row first and then erasing the old one won't work either because Id is a primary key and is unique.

    Thanks for your help!!!
    Last edited by nacho2; Dec 10th, 2004 at 10:42 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: Trying again!!

    Hi guys does anyone have any idea on how to do this?

    Thanks

  3. #3
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Trying again!!

    Hi Nacho2
    I think you won't get much help from the forum because no one in its in right mind would consider xml as a database engine : use access, ms sql, msde,mysql, etc...

    Anyway check the System.Xml.XmlDataDocument class that allows for xml node managment.

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: Trying again!!

    Ok, Jorge, you are probably right but I think it is basically the same. If I were using a SQL database I would fill my dataset and then make changes to it and afterwards send those changes to the database. So I don't think it makes a big difference where you are storing your data, the only differences are between the dataset and the database whereas my questions are about the 'space' between the dataset and the user. Does it make sense?

    If you had a SQL and filled a Dataset, how would you retrieve data from the dataset to show the user? Using dataset.select(..)? And how would you make changes to the dataset?

  5. #5
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Trying again!!

    Ok, this is how i make a update to a datarow. I have a datatable named m_DataTable with 3 datacollumn named 'Column0','Column1' and 'Column2'. I added to the datatable 3 datarows initially with the values (1,2,3), (4,9,12) and (77, 192,0).
    Code:
            m_DataTable.AcceptChanges()
            '' update 1st row
            m_DataTable.Rows(0)("Column0") = "cat"
            m_DataTable.Rows(0)("Column1") = "dog"
            m_DataTable.Rows(0)("Column2") = "horse"
            '' update 2nd row
            m_DataTable.Rows(1)("Column0") = "cat"
            m_DataTable.Rows(1)("Column1") = "dog"
            m_DataTable.Rows(1)("Column2") = "horse"
            '' update 3rd row
            m_DataTable.Rows(2)("Column0") = "cat"
            m_DataTable.Rows(2)("Column1") = "dog"
            m_DataTable.Rows(2)("Column2") = "horse"
    
            Me.DataGrid1.DataSource = m_DataTable
    Once you modified the datarows just update your xml files with the dataset.

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: Trying again!!

    Ok great that's what I needed.

    Now one more thing, what if I don't know the row index? Let's say it is a table of customers having each customer an IdCustomer. How can I get the row index that corresponds to the row with the IdCustomer I have?

    I've tried doing:

    DataSchema1.Clientes.Select("IdCustomer=" & var)
    DataSchema1.Clientes.Rows(0)("Name") = "NewName"
    DataSchema1.WriteXml("..\Data.xml")

    I did the select first thinking that that would leave DataSchema1.Clientes with only the row with IdCustomer= var but I guess I would have to store it somewhere, and not just the method.

    So then I thought there may be some method to get the row index of certain row.

    Any ideas?

    Thanks

  7. #7
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Trying again!!

    Quote Originally Posted by nacho2
    Ok great that's what I needed.

    Now one more thing, what if I don't know the row index? Let's say it is a table of customers having each customer an IdCustomer. How can I get the row index that corresponds to the row with the IdCustomer I have?

    I've tried doing:

    DataSchema1.Clientes.Select("IdCustomer=" & var)
    DataSchema1.Clientes.Rows(0)("Name") = "NewName"
    DataSchema1.WriteXml("..\Data.xml")

    I did the select first thinking that that would leave DataSchema1.Clientes with only the row with IdCustomer= var but I guess I would have to store it somewhere, and not just the method.

    So then I thought there may be some method to get the row index of certain row.

    Any ideas?

    Thanks
    Hi
    Try this
    Code:
    Dim filter As String = "IdCustomer='" & var & "'"
    Dim r As DataRow() = DataSchema1.Clientes.Select(filter)
    For j As Integer = 0 To r.Length - 1
        MessageBox.Show(r(j).Item(1).ToString)
    Next
    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: Trying again!!

    Thanks Jorge,

    I already figured out that there was no predefined function to get the row index so I wrote my own, which looks a lot like yours.

    I really appreaciate your help, thank you very much.

    Gracias!

    Nacho

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Trying again!!

    You can also use the Select method you mentioned before to get an array of datarows that meet your criteria and then change the value. That should be faster than looping to find it.

    Code:
    Dim dr() As DataRow=DataTable1.Select(String.Format("IdCustomer={0}",var))
    If dr.Length > 0 Then
       dr(0)("Erased")=False
    End If

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