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
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
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
Utsavp
Member
22 Points
55 Posts
Showing confirmation message.
May 11, 2010 06:18 AM|LINK
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 SubPlease it is Urgent
rizwanparkar
Contributor
2394 Points
421 Posts
Re: Showing confirmation message.
May 11, 2010 07:40 AM|LINK
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 SubIf the post helps you, please Mark it As Answer.
regards
-------------------
Rizwan Hanif Parkar
Vijaya.A
Contributor
2408 Points
629 Posts
Re: Showing confirmation message.
May 11, 2010 07:50 AM|LINK
Hi follow code mentioned by rizwanparkar but in finally u should dispose (OriginalDataSet.Dispose())
Utsavp
Member
22 Points
55 Posts
Re: Showing confirmation message.
May 11, 2010 07:55 AM|LINK
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.
Utsavp
Member
22 Points
55 Posts
Re: Showing confirmation message.
May 11, 2010 08:00 AM|LINK
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..
Vijaya.A
Contributor
2408 Points
629 Posts
Re: Showing confirmation message.
May 11, 2010 08:08 AM|LINK
Hi declare "OriginalDataSet" above try
Vijaya.A
Contributor
2408 Points
629 Posts
Re: Showing confirmation message.
May 11, 2010 08:10 AM|LINK
use page.clientscript....
Utsavp
Member
22 Points
55 Posts
Re: Showing confirmation message.
May 11, 2010 08:36 AM|LINK
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 TryVijaya.A
Contributor
2408 Points
629 Posts
Re: Showing confirmation message.
May 11, 2010 08:46 AM|LINK
Hi it is not showing any error for me and working fine for me
Utsavp
Member
22 Points
55 Posts
Re: Showing confirmation message.
May 11, 2010 08:55 AM|LINK
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.