Inserting XML Data Into a New Table FROM VB.NET
From: sql_Michael_dotnet (mroud_at_yahoo.com)
Date: 06/25/04
- Next message: gary b: "Parameterized queries running slower than non-parameterized queries"
- Previous message: sqlguy: "Rights to the tables disappear from the role."
- Messages sorted by: [ date ] [ thread ]
Date: 25 Jun 2004 08:45:36 -0700
Can anyone help me figure out how to insert data into SQL Server when
a table to hold the data does not yet exist. I am able to insert data
into a existing table in the following fashion. But what if the table
does not exist? Appreciate any help I can get.
Private Sub InsertData()
Dim objSQLConn As New
SqlConnection("SERVER=.;UID=sa;PWD=;DATABASE=MyTest;")
Dim objAdapter As SqlDataAdapter
Dim objDataRow As DataRow 'Dataset row
Dim objDBRow As DataRow 'SQL Server table row
Dim objDSXML As New DataSet
Dim objDSDBTable As New DataSet("People")
Dim ObjCmdBuilder As SqlCommandBuilder
objDSXML.ReadXml("C:\myXML.xml")
objSQLConn.Open()
objAdapter = New SqlDataAdapter("SELECT * FROM People WHERE 1
= 2 ", objSQLConn)
objAdapter.Fill(objDSDBTable, "People")
For Each objDataRow In objDSXML.Tables(0).Rows
With objDSDBTable.Tables(0)
objDBRow = .NewRow()
objDBRow(0) = objDataRow(0)
objDBRow(1) = objDataRow(1)
.Rows.Add(objDBRow)
End With
ObjCmdBuilder = New SqlCommandBuilder(objAdapter)
objAdapter.Update(objDSDBTable, "People")
Next
objSQLConn.Close()
End Sub
- Next message: gary b: "Parameterized queries running slower than non-parameterized queries"
- Previous message: sqlguy: "Rights to the tables disappear from the role."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|