Merci bcp Charles,
enfin g réussi à rédiger un bout de code pour résoudre le pb, le voila:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
Private Sub ImportData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportData.Click
'create a dataSet
Dim dataSetXml As DataSet
Dim dataTableXml As DataTable
Dim connString, sqlCmd, tableName As String
Dim i, x As Integer
Dim conn As SqlConnection
'Load the xml file into a dataSet
'DataSetXml.ReadXml(httpContext.Current.Server.MapPath(textBoxXml.Text));
dataSetXml.ReadXml(textBoxXml.Text)
'Get the first table in the DataSet
dataTableXml = dataSetXml.Tables(0)
'verify the table contains data
If (dataTableXml.Rows.Count > 0) Then
'cerate an sql connection
connString = TextBoxSql.Text
conn.Open()
'create a temporary table in the dataBase
'use the xml file's name for the temporary table
tableName = TextBoxXml.Text.Substring(0, TextBoxXml.TextLength - 4)
'make the create table SQL command by iterating throught the xml file's coulumns
'This way the dataBase columns will have the same name as the xml file
sqlCmd = "create table #" + tableName + "("
For i = 0 To dataTableXml.Columns.Count
'this adds columns as string type with a length of 100
sqlCmd = sqlCmd + dataTableXml.Columns(i).ColumnName.ToString() + "char(100),"
Next
'remove the last ","
sqlCmd = sqlCmd.Substring(0, sqlCmd.Length - 1) + ")"
'create and exute the create table command
Dim command As SqlCommand(sqlCmd,conn)
Command(sqlCmd, conn).ExecuteNonQuery()
'iterate rows in the dataTable
For Each dr As DataRow In dataTableXml.Rows
'create the sql insert command for each row
sqlCmd = "insert into [" + tableName + "] ("
'iterate the dataTable columns
For i = 0 To dataTableXml.Columns.Count
'add the column name
sqlCmd = sqlCmd + dataTableXml.Columns(i).ColumnName.ToString() + ","
Next
'remove the last ","
sqlCmd = sqlCmd.Substring(0, sqlCmd.Length - 1) + ") values ("
'iterate the dataTable columns
For x = 0 To dataTableXml.Columns.Count
'add the column value for this row
sqlCmd = sqlCmd + "'" + dr(x).ToString().Replace("'", "''") + "'"
Next
sqlCmd = sqlCmd.Substring(0, sqlCmd.Length - 1) + ");"
'create and execute the insert command
Dim command As SqlCommand(sqlCmd,conn)
Command(sqlCmd, conn)
Next
End If
End Sub
End Class
l'affichage ne serait pas agréable, désolée, j'espère qu' un gentil modérateur le prendra en charge
Bref, il ya qd même des erreurs (2 principales qui consernent l'objet command)
si vous découvrez la solution merci de m'informer
le code a un autre incovénient c qu'il n'est pas modulaire, j'essayerai de le faire plus tard
je suis débutante en codage et j'apprécierai tout conseil de la part des menmbres
à bien tôt ;)