Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
End If
End Sub
Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim I As Integer
For I = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(I).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(I).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(I).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href='" + ServerUrl + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml'>" + schemaTable.Rows(I).ItemArray(2).ToString() + ".xml</a><br/>"
Next I
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub