Carobit Logo
Valid HTML 4.01!

Your Connection
  guest
Log out
Log in or Sign Up
Site Navigation
  Home
Forum Home
Closed Conversations
For Members
  Support
Feedback
Member Search
Carobit Mail
Helpful Links
  Smilies
Formatting
Preview
Originator: LukeW Printable Version
Title: VB Datasets help
Back to Lounge

Attachments Add Attachment

History
From: Send Carobit Mail LukeW On: 2008/07/18 19:33:28
If anyones got any time spare they could maybe help me with my VB dataset issues.

All this has been put together from various sources so could be the wrong way to go about.


Heres the code that works perfectly to let you modify the xml in an grid and save it where you specify as an xml again.





Imports System.IO

Public Class frmTech


    Private Sub ReadXmlButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles btnReadXML.Click


        Dim dlgRead As New OpenFileDialog
        Dim filePath As String
        Dim Header As String = txtHead.Text


        If dlgRead.ShowDialog() = DialogResult.OK Then

            filePath = dlgRead.FileName
            DataSet.ReadXml(filePath)
            grdMain.DataSource = DataSet
            grdMain.DataMember = Header

        End If

    End Sub






    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles btnSave.Click




        Dim swXML As New System.IO.StringWriter()
        Dim dlgWrite As New SaveFileDialog
        Dim filepath As String

        dlgWrite.Filter = "XML files (*.xml)|*.xml"

        If dlgWrite.ShowDialog() = DialogResult.OK Then

            filepath = dlgWrite.FileName

            DataSet.WriteXml(filepath)
            grdMain.DataSource = Nothing
            grdMain.Refresh()
            DataSet.Reset()
        End If

    End Sub

   
End Class









//bein question

Now in the dataset table is lots of records, 4 colums ID(string), X and Y, Z populated with integers, how could I make Z = X + Y for all records at once.

If I can manipulate it in the dataset / grid using a command of some sort then my save will do the rest.

I think its something basic (manipulating datasets) but im learning vb online by trial and error and been stuck here for a while now :(

//End q

Thanks

From: Send Carobit Mail PaulHews On: 2008/07/18 19:50:50
You can do it by adding an expression to a column, which will then compute that value for you:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dt As New DataTable
        dt.Columns.Add("X", GetType(Integer))
        dt.Columns.Add("Y", GetType(Integer))
        dt.Columns.Add(("Z"), GetType(Integer))
        For i As Integer = 1 To 10
            Dim Row As DataRow = dt.NewRow
            Row("X") = 4 * i
            Row("Y") = 5 * i
            dt.Rows.Add(Row)
        Next

       
        dt.Columns("Z").Expression = "X+Y"

        DataGridView1.DataSource = dt


    End Sub
End Class

From: Send Carobit Mail LukeW On: 2008/07/19 04:53:32
Thanks a lot for this will take a look tonight, unfortunately im so slow it will take me a day or two to find out if im getting there. :)


From: Send Carobit Mail LukeW On: 2008/07/19 15:35:08
Thanks a lot for this will take a look tonight, unfortunately im so slow it will take me a day or two to find out if im getting there. :)



Oops refreshed when I rebooted :( - cant delete

Enter your comments here

As a guest you will only be able to see what a comment posted by you would look like by clicking the Preview button. You can't actually participate by posting comments to this conversation.

Number of viewers: 12