Need to get empty datatable in .net with database table schema

前端 未结 10 839
闹比i
闹比i 2021-02-07 04:40

What is the best way to create an Empty DataTable object with the schema of a sql server table?

10条回答
  •  别跟我提以往
    2021-02-07 05:16

    Class BlankTableWithSourceTableSchema
        Inherits DataTable
        Public Sub New(ByVal connstr As String, ByVal sourcetable As String)
            Try
                Using connection As SqlServerCe.SqlCeConnection = New SqlServerCe.SqlCeConnection(connstr)
                    Dim adapter As SqlServerCe.SqlCeDataAdapter = New SqlServerCe.SqlCeDataAdapter("SELECT * FROM " & sourcetable, connection)
                    adapter.TableMappings.Add("Table", "ABlankTable")
                    adapter.FillSchema(Me, SchemaType.Mapped)
                End Using
            Catch ex As Exception
            End Try
        End Sub
    End Class
    

提交回复
热议问题