Write XML file from sql database in vb.net also example of sql connection with OleDbDataAdapter control.
Know More :   ASP.Net  VB.Net
ASP.Net  VB.Net C#.Net
  C#.Net Sliverlight
  Sliverlight XML
  XML WPF
  WPF WCF
  WCF Ajax
 Ajax
Let's start with Microsoft visual studio 2008\2005\2003 using language Microsoft vb.net.Create a new project name "create xml file from Microsoft sql database". Also Microsoft Sql server 2008 \2005 express or evaluation Open run command and type "devenv" after press enter. After open Microsoft visual studio go to file menu and select new project or as shown in figure like this..
Now Left pane select vb.net , after select vb.net language go to templates and select windows form application also type the name according to you in the name box click on OK button.Now form1 will be open as shown in figure.. 
                          
After drag ,drop and rename buttons on form design. Now double click on create directory button , Also declare namespace above the public class
Imports System.Threading.Thread
Imports System.IO
                                                       
Private Sub createDirectorybutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createDirectorybutton1.Click
Directory.CreateDirectory("d:\\AC_backup") 'you can change your location
MessageBoxEx.Show("Backup Folder created in d:\AC_Backup ", "Sujay Application", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
                                        
check your directory is created or not in d:\\AC_backup this directory. After directory created we will create xml file from sql database. Before create xml file from sql database , first create a connection with "OleDbDataAdapter" control . Drag OleDbDataAdapter control from toolbox on form after drop this control a dataadapter configuration wizard is open as shown in figure..
                                               
                                          
if you have already create a connection then click on next button if not then click on new connection button as shown figure , after click on new connection a add connection windows open like this figure..
                                       
                                                                                                                
After create a connection , click on next button...After click on next button , will be open new window as shown in figure ..then click on Query bulider button                                                                    
                                                                                           
                                                                                           
Next shown in figure..do this
                                          
Next shown in figure..do this
                                       
Next shown in figure..do this
 
                                            
Next shown in figure..do this
                                           
Click on Ok Button .Next shown in figure..do this
                                       
Next shown in figure..do this
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
                                                                                       
After click on finish button.Next shown in figure..do this
                                       
Type the name of dataset and click OK as shown in figure..
Now your connection is completed.After complete a connection write a code to button event for create a xml file from sql database. First , declare namspace
                                                                                           
Imports System.Data.SqlClient
Imports System.Data.OleDb
                                                                                           
Now double click on create xml file button and write code as given ..
                                                                                           
Try
Dim MyConnection1 As SqlConnection = New SqlConnection("server=.\SQLEXPRESS;database=Assoc_comp;Trusted_Connection=yes")
Dim MyCommand1 As SqlDataAdapter = New SqlDataAdapter("select * from Employee", MyConnection1)
Dim DS As New DataSet()
MyCommand1.Fill(DS, "Employee")
DS.WriteXmlSchema("d:\AC_backup\Employee.xsd")
DS.WriteXml("d:\AC_backup\Employee.xml")
Catch ex As SqlException
MessageBox.Show(ex.Message, "Sujay Application", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
                                                                                           
Now you have to completed create a xml file from sql database. Check xml file ---> go to directory 'd:\AC_backup\' double clickon employee.xml file --> tthe xml file will be open in browser also contain your data from sql database. Thanks.
Know More : ASP.Net  VB.Net
ASP.Net  VB.Net C#.Net
  C#.Net Sliverlight
  Sliverlight XML
  XML WPF
  WPF WCF
  WCF Ajax
 Ajax
Let's start with Microsoft visual studio 2008\2005\2003 using language Microsoft vb.net.Create a new project name "create xml file from Microsoft sql database". Also Microsoft Sql server 2008 \2005 express or evaluation Open run command and type "devenv" after press enter. After open Microsoft visual studio go to file menu and select new project or as shown in figure like this..
Now Left pane select vb.net , after select vb.net language go to templates and select windows form application also type the name according to you in the name box click on OK button.Now form1 will be open as shown in figure..
 
                          After drag ,drop and rename buttons on form design. Now double click on create directory button , Also declare namespace above the public class
Imports System.Threading.Thread
Imports System.IO
Private Sub createDirectorybutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createDirectorybutton1.Click
Directory.CreateDirectory("d:\\AC_backup") 'you can change your location
MessageBoxEx.Show("Backup Folder created in d:\AC_Backup ", "Sujay Application", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
check your directory is created or not in d:\\AC_backup this directory. After directory created we will create xml file from sql database. Before create xml file from sql database , first create a connection with "OleDbDataAdapter" control . Drag OleDbDataAdapter control from toolbox on form after drop this control a dataadapter configuration wizard is open as shown in figure..
if you have already create a connection then click on next button if not then click on new connection button as shown figure , after click on new connection a add connection windows open like this figure..
Next shown in figure..do this
Next shown in figure..do this
Next shown in figure..do this
 
                                            Next shown in figure..do this
Click on Ok Button .Next shown in figure..do this
Next shown in figure..do this
After click on finish button.Next shown in figure..do this
Type the name of dataset and click OK as shown in figure..
Now your connection is completed.After complete a connection write a code to button event for create a xml file from sql database. First , declare namspace
Imports System.Data.SqlClient
Imports System.Data.OleDb
Now double click on create xml file button and write code as given ..
Try
Dim MyConnection1 As SqlConnection = New SqlConnection("server=.\SQLEXPRESS;database=Assoc_comp;Trusted_Connection=yes")
Dim MyCommand1 As SqlDataAdapter = New SqlDataAdapter("select * from Employee", MyConnection1)
Dim DS As New DataSet()
MyCommand1.Fill(DS, "Employee")
DS.WriteXmlSchema("d:\AC_backup\Employee.xsd")
DS.WriteXml("d:\AC_backup\Employee.xml")
Catch ex As SqlException
MessageBox.Show(ex.Message, "Sujay Application", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Now you have to completed create a xml file from sql database. Check xml file ---> go to directory 'd:\AC_backup\' double clickon employee.xml file --> tthe xml file will be open in browser also contain your data from sql database. Thanks.
Know More :
 
 
                       









 
 

No comments