locked
Showing confirmation message. RRS feed

  • Question

  • User-1745705970 posted

    Hi,

    The following codes insert the Data inside the XML file using the ADD NEW USER Form. Now i want to display the confirmation message to the User's that the Data has been Successfully added or Data not inserted message. Also i want to know how to add TRY, CATCH and FINALLY method in this code. Pls edit my code and send me. ]

    CODE:

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
            ' Create a DataSet with one table and three columns.
            Dim OriginalDataSet As New DataSet("myDataSet")
            OriginalDataSet.Namespace = "NetFrameWork"
            Dim myTable As New DataTable("myTable")
            Dim c1 As New DataColumn("AccNumber", Type.GetType("System.Int32"))
            'c1.AutoIncrement = True
            Dim c2 As New DataColumn("Name", Type.GetType("System.String"))
            Dim c3 As New DataColumn("Balance$", Type.GetType("System.Double"))
    
    
            myTable.Columns.Add(c1)
            myTable.Columns.Add(c2)
            myTable.Columns.Add(c3)
    
            OriginalDataSet.Tables.Add(myTable)
    
            Dim newRow As DataRow
            newRow = myTable.NewRow()
            newRow("AccNumber") = txtAccNumber.Text.ToString()
    
            newRow("Name") = txtName.Text.ToString()
            newRow("Balance$") = txtBalance.Text.ToString()
            myTable.Rows.Add(newRow)
    
    
            OriginalDataSet.AcceptChanges()
    
            ' Write the schema and data to an XML file.
            Dim xmlFilename As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Demo_aps\Demo_aps\myXmlDocument.xml"
            ' Use WriteXml to write the document.
            OriginalDataSet.WriteXml(xmlFilename)
    
            ' Dispose of the original DataSet.
            OriginalDataSet.Dispose()
    
        End Sub


    Tuesday, May 11, 2010 2:18 AM

Answers

  • User406085191 posted

    Hi Vijaya.A

    Ya i did as u said that:  OriginalDataSet.Dispose() inside the finally block.

    but it also showed me error: Name "OriginalDataSet" is not Declared.

    Pls can u help me..

     

    Hi declare "OriginalDataSet" above try

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 11, 2010 4:08 AM
  • User406085191 posted

    Hi I just  modified ur above code

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
    
            ' Create a DataSet with one table and three columns.
    
            Dim OriginalDataSet As New DataSet("myDataSet")
            OriginalDataSet.Namespace = "NetFrameWork"
            Dim myTable As New DataTable("myTable")
            Dim c1 As New DataColumn("AccNumber", Type.GetType("System.Int32"))
            'c1.AutoIncrement = True
            Dim c2 As New DataColumn("Name", Type.GetType("System.String"))
            Dim c3 As New DataColumn("Balance$", Type.GetType("System.Double"))
    
    
            myTable.Columns.Add(c1)
            myTable.Columns.Add(c2)
            myTable.Columns.Add(c3)
    
            OriginalDataSet.Tables.Add(myTable)
            Try
                Dim newRow As DataRow
                newRow = myTable.NewRow()
                newRow("AccNumber") = txtAccNumber.Text.ToString()
    
                newRow("Name") = txtName.Text.ToString()
                newRow("Balance$") = txtBalance.Text.ToString()
                myTable.Rows.Add(newRow)
    
    
                OriginalDataSet.AcceptChanges()
    
                ' Write the schema and data to an XML file.
                Dim xmlFilename As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Demo_aps\Demo_aps\myXmlDocument.xml"
                ' Use WriteXml to write the document.
                OriginalDataSet.WriteXml(xmlFilename)
    
                'OriginalDataSet.Dispose()
    
                ' Dispose of the original DataSet.
                'MessageBox.Show("Inserted Successfully")
                'Me.Hide()
    
    
                MsgBox("Success”)
            Catch ex As Exception
    
                MsgBox("Failure”)
    
            Finally
    
                OriginalDataSet.Dispose()
    
            End Try
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 11, 2010 5:31 AM

All replies

  • User-1645128838 posted

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
            Try
    
                ' Create a DataSet with one table and three columns.
                Dim OriginalDataSet As New DataSet("myDataSet")
                OriginalDataSet.Namespace = "NetFrameWork"
                Dim myTable As New DataTable("myTable")
                Dim c1 As New DataColumn("AccNumber", Type.GetType("System.Int32"))
                'c1.AutoIncrement = True
                Dim c2 As New DataColumn("Name", Type.GetType("System.String"))
                Dim c3 As New DataColumn("Balance$", Type.GetType("System.Double"))
    
    
                myTable.Columns.Add(c1)
                myTable.Columns.Add(c2)
                myTable.Columns.Add(c3)
    
                OriginalDataSet.Tables.Add(myTable)
    
                Dim newRow As DataRow
                newRow = myTable.NewRow()
                newRow("AccNumber") = txtAccNumber.Text.ToString()
    
                newRow("Name") = txtName.Text.ToString()
                newRow("Balance$") = txtBalance.Text.ToString()
                myTable.Rows.Add(newRow)
    
    
                OriginalDataSet.AcceptChanges()
    
                ' Write the schema and data to an XML file.
                Dim xmlFilename As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Demo_aps\Demo_aps\myXmlDocument.xml"
                ' Use WriteXml to write the document.
                OriginalDataSet.WriteXml(xmlFilename)
    
                ' Dispose of the original DataSet.
                OriginalDataSet.Dispose()
    
                ClientScript.RegisterClientScriptBlock(GetType(Page), "", "alert('success');", True)
    
            Catch ex As Exception
                ClientScript.RegisterClientScriptBlock(GetType(Page), "", "alert('failure');", True)
            End Try
        End Sub


    Tuesday, May 11, 2010 3:40 AM
  • User406085191 posted

     Hi follow code mentioned by rizwanparkar but in finally u should dispose (OriginalDataSet.Dispose())

    Tuesday, May 11, 2010 3:50 AM
  • User-1745705970 posted

    Hi rizwanparker,

    It showed two error message. after i edited the code as you provided.

    Name Clientscript is not declared

    Type page is not defined.



    Tuesday, May 11, 2010 3:55 AM
  • User-1745705970 posted

    Hi Vijaya.A

    Ya i did as u said that:  OriginalDataSet.Dispose() inside the finally block.

    but it also showed me error: Name "OriginalDataSet" is not Declared.

    Pls can u help me..

    Tuesday, May 11, 2010 4:00 AM
  • User406085191 posted

    Hi Vijaya.A

    Ya i did as u said that:  OriginalDataSet.Dispose() inside the finally block.

    but it also showed me error: Name "OriginalDataSet" is not Declared.

    Pls can u help me..

     

    Hi declare "OriginalDataSet" above try

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 11, 2010 4:08 AM
  • User406085191 posted

    Hi rizwanparker,

    It showed two error message. after i edited the code as you provided.

    Name Clientscript is not declared

    Type page is not defined.



     

    use page.clientscript....

    Tuesday, May 11, 2010 4:10 AM
  • User-1745705970 posted

    Still it shows Page is Not declared


    View my code again.


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
    
            ' Create a DataSet with one table and three columns.
    
            Dim OriginalDataSet As New DataSet("myDataSet")
            OriginalDataSet.Namespace = "NetFrameWork"
            Dim myTable As New DataTable("myTable")
            Dim c1 As New DataColumn("AccNumber", Type.GetType("System.Int32"))
            'c1.AutoIncrement = True
            Dim c2 As New DataColumn("Name", Type.GetType("System.String"))
            Dim c3 As New DataColumn("Balance$", Type.GetType("System.Double"))
    
    
            myTable.Columns.Add(c1)
            myTable.Columns.Add(c2)
            myTable.Columns.Add(c3)
    
            OriginalDataSet.Tables.Add(myTable)
            Try
                Dim newRow As DataRow
                newRow = myTable.NewRow()
                newRow("AccNumber") = txtAccNumber.Text.ToString()
    
                newRow("Name") = txtName.Text.ToString()
                newRow("Balance$") = txtBalance.Text.ToString()
                myTable.Rows.Add(newRow)
    
    
                OriginalDataSet.AcceptChanges()
    
                ' Write the schema and data to an XML file.
                Dim xmlFilename As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Demo_aps\Demo_aps\myXmlDocument.xml"
                ' Use WriteXml to write the document.
                OriginalDataSet.WriteXml(xmlFilename)
    
                'OriginalDataSet.Dispose()
    
                ' Dispose of the original DataSet.
                'MessageBox.Show("Inserted Successfully")
                'Me.Hide()
    
    
                Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "", "alert('success');", True)
    
            Catch ex As Exception
    
                Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "", "alert('failure');", True)
    
    
            Finally
    
                OriginalDataSet.Dispose()
    
            End Try


    Tuesday, May 11, 2010 4:36 AM
  • User406085191 posted

    Hi it is not showing any error for me and working fine for me

     

    Tuesday, May 11, 2010 4:46 AM
  • User-1745705970 posted

    hi Please can u say me why i am getting error message:

    Name "Page" is not declared and

    Type "Page" is not declared.


    Am i missing any Library or Class that supports the Page.



    Tuesday, May 11, 2010 4:55 AM
  • User406085191 posted

    Hi r u using windows application or web application

    if ur using  windows application use msgbox-- for displaying msg success

    if ur using web application import System.Web.UI

    Tuesday, May 11, 2010 4:59 AM
  • User-1745705970 posted

    I am just using windows application.

    Now how to use the MsgBox in such a Situation...  Please reply..


    Tuesday, May 11, 2010 5:16 AM
  • User406085191 posted

    Hi use this code

    MsgBox("Your Message") instead of page.register.........

    Tuesday, May 11, 2010 5:21 AM
  • User-1745705970 posted

    can u send me a code. Please give me a complete answer.



    Tuesday, May 11, 2010 5:28 AM
  • User406085191 posted

    Hi I just  modified ur above code

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
    
            ' Create a DataSet with one table and three columns.
    
            Dim OriginalDataSet As New DataSet("myDataSet")
            OriginalDataSet.Namespace = "NetFrameWork"
            Dim myTable As New DataTable("myTable")
            Dim c1 As New DataColumn("AccNumber", Type.GetType("System.Int32"))
            'c1.AutoIncrement = True
            Dim c2 As New DataColumn("Name", Type.GetType("System.String"))
            Dim c3 As New DataColumn("Balance$", Type.GetType("System.Double"))
    
    
            myTable.Columns.Add(c1)
            myTable.Columns.Add(c2)
            myTable.Columns.Add(c3)
    
            OriginalDataSet.Tables.Add(myTable)
            Try
                Dim newRow As DataRow
                newRow = myTable.NewRow()
                newRow("AccNumber") = txtAccNumber.Text.ToString()
    
                newRow("Name") = txtName.Text.ToString()
                newRow("Balance$") = txtBalance.Text.ToString()
                myTable.Rows.Add(newRow)
    
    
                OriginalDataSet.AcceptChanges()
    
                ' Write the schema and data to an XML file.
                Dim xmlFilename As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Demo_aps\Demo_aps\myXmlDocument.xml"
                ' Use WriteXml to write the document.
                OriginalDataSet.WriteXml(xmlFilename)
    
                'OriginalDataSet.Dispose()
    
                ' Dispose of the original DataSet.
                'MessageBox.Show("Inserted Successfully")
                'Me.Hide()
    
    
                MsgBox("Success”)
            Catch ex As Exception
    
                MsgBox("Failure”)
    
            Finally
    
                OriginalDataSet.Dispose()
    
            End Try
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 11, 2010 5:31 AM
  • User-1588418485 posted

    follow the code by vijaya mam..its perfect

    Tuesday, May 11, 2010 5:36 AM
  • User-1745705970 posted

    Ok thank u very Much. At last My Code looks like:


        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
    
            ' Create a DataSet with one table and three columns.
    
            Dim OriginalDataSet As New DataSet("myDataSet")
            OriginalDataSet.Namespace = "NetFrameWork"
            Dim myTable As New DataTable("myTable")
            Dim c1 As New DataColumn("AccNumber", Type.GetType("System.Int32"))
            'c1.AutoIncrement = True
            Dim c2 As New DataColumn("Name", Type.GetType("System.String"))
            Dim c3 As New DataColumn("Balance$", Type.GetType("System.Double"))
    
    
            myTable.Columns.Add(c1)
            myTable.Columns.Add(c2)
            myTable.Columns.Add(c3)
    
    
            OriginalDataSet.Tables.Add(myTable)
            Try
                Dim newRow As DataRow
                newRow = myTable.NewRow()
                newRow("AccNumber") = txtAccNumber.Text.ToString()
    
                newRow("Name") = txtName.Text.ToString()
                newRow("Balance$") = txtBalance.Text.ToString()
                myTable.Rows.Add(newRow)
    
    
                OriginalDataSet.AcceptChanges()
    
                ' Write the schema and data to an XML file.
                Dim xmlFilename As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Demo_aps\Demo_aps\myXmlDocument.xml"
                ' Use WriteXml to write the document.
                OriginalDataSet.WriteXml(xmlFilename)
    
                'OriginalDataSet.Dispose()
    
                ' Dispose of the original DataSet.
                'MessageBox.Show("Inserted Successfully")
                'Me.Hide()
    
    
                MsgBox("Data Inserted Successfully")
    
            Catch ex As Exception
    
                MsgBox("Field Missing: Unable to Insert Data.")
    
    
            Finally
    
                OriginalDataSet.Dispose()
    
            End Try
    
        End Sub



    Tuesday, May 11, 2010 5:40 AM
  • User-1745705970 posted

    Thank u very much. My code looks like this after error is free


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
    
            ' Create a DataSet with one table and three columns.
    
            Dim OriginalDataSet As New DataSet("myDataSet")
            OriginalDataSet.Namespace = "NetFrameWork"
            Dim myTable As New DataTable("myTable")
            Dim c1 As New DataColumn("AccNumber", Type.GetType("System.Int32"))
            'c1.AutoIncrement = True
            Dim c2 As New DataColumn("Name", Type.GetType("System.String"))
            Dim c3 As New DataColumn("Balance$", Type.GetType("System.Double"))
    
    
            myTable.Columns.Add(c1)
            myTable.Columns.Add(c2)
            myTable.Columns.Add(c3)
    
    
            OriginalDataSet.Tables.Add(myTable)
            Try
                Dim newRow As DataRow
                newRow = myTable.NewRow()
                newRow("AccNumber") = txtAccNumber.Text.ToString()
    
                newRow("Name") = txtName.Text.ToString()
                newRow("Balance$") = txtBalance.Text.ToString()
                myTable.Rows.Add(newRow)
    
    
                OriginalDataSet.AcceptChanges()
    
                ' Write the schema and data to an XML file.
                Dim xmlFilename As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Demo_aps\Demo_aps\myXmlDocument.xml"
                ' Use WriteXml to write the document.
                OriginalDataSet.WriteXml(xmlFilename)
    
                'OriginalDataSet.Dispose()
    
                ' Dispose of the original DataSet.
                'MessageBox.Show("Inserted Successfully")
                'Me.Hide()
    
    
                MsgBox("Data Inserted Successfully")
    
            Catch ex As Exception
    
                MsgBox("Field Missing: Unable to Insert Data.")
    
    
            Finally
    
                OriginalDataSet.Dispose()
    
            End Try
    
        End Sub
    
    
    


    Tuesday, May 11, 2010 5:52 AM