Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bulkcopy blues
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Bulkcopy blues
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01531608
Message ID:
01531608
Vues:
112
Update: There's a good reason why the "destination table" cannot be found, it does not exist. I assumed that sqlserver creates the destination table.

I use vb2010 express and sql server 2008 R2 express. So it might also be a "you get what you pay for" problem if bulkcopy is not supported in express. Could not find any evidence of that though.

If this works ....
   Public Sub sqlcreatetable()
        Dim oconn As New SqlClient.SqlConnection(My.Settings.p0030ConnectionString)
        oconn.Open()
        Dim ocmd As New SqlClient.SqlCommand()
        ocmd.Connection = oconn
        ocmd.CommandText = "drop table temp"
        Try
            ocmd.ExecuteNonQuery()
        Catch
        End Try
        ocmd.CommandText = "create table temp (f1 int) "
        ocmd.ExecuteNonQuery()
    End Sub
Why do I get "Could not access table" in the
oBC.WriteToServer(odt)
statement?
   Public Shared Sub bulkcopy(ByVal odt As DataTable, ByVal cTableName As String)
        Dim oConn As New SqlClient.SqlConnection(My.Settings.p0030ConnectionString)
        oConn.Open()
        oConn.Close()

        Dim oBC As New SqlClient.SqlBulkCopy(My.Settings.p0030ConnectionString)
        oBC.DestinationTableName = cTableName
        oBC.WriteToServer(odt)
    End Sub
    Public Shared Sub test()
        Dim oconn As New SqlClient.SqlConnection(My.Settings.p0030ConnectionString)
        oconn.Open()
        Dim oCmd As New SqlClient.SqlCommand("select * from config", oconn)
        Dim oDa As New SqlClient.SqlDataAdapter(oCmd)
        Dim oDt As New DataTable
        oDa.Fill(oDt)
        oconn.Close()
        fwDataTable.bulkcopy(oDt, "Temp5")
    End Sub

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Répondre
Fil
Voir

Click here to load this message in the networking platform