D
DavidA
I am trying to copy data from a table in one database to an identical
table in another database.
The first table (WOS) contains 11 records, the second (WOSAdmin) is
empty.
The problem is that the data is never inserted into the second table.
Can anyone explain what I am doing wrong?
Definitions of the tables and the code I am using below:
USE [WOS]
GO
/****** Object: Table [dbo].[MembershipCategory] Script Date:
01/21/2006 21:48:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MembershipCategory](
[TypeOfMember] [smallint] NOT NULL,
[MembershipType] [nvarchar](50) COLLATE Latin1_General_CI_AS
NULL,
[AnnualFee] [money] NULL,
[JoiningFee] [money] NULL,
CONSTRAINT [PK_MembershipCategory] PRIMARY KEY CLUSTERED
(
[TypeOfMember] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
USE [WOSAdmin]
GO
/****** Object: Table [dbo].[MembershipCategory] Script Date:
01/21/2006 21:47:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MembershipCategory](
[TypeOfMember] [smallint] NOT NULL,
[MembershipType] [nvarchar](50) COLLATE Latin1_General_CI_AS
NULL,
[AnnualFee] [money] NULL,
[JoiningFee] [money] NULL,
CONSTRAINT [PK_MembershipCategory] PRIMARY KEY CLUSTERED
(
[TypeOfMember] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Dim conn As New SqlConnection
Dim da As New SqlDataAdapter
Dim connString As String = "data
source=RUATHA\SQLEXPRESS;Initial Catalog=WOS;Integrated Security=True"
conn.ConnectionString = connString
conn.Open()
Dim cmdString As String = "select TypeOfMember,
MembershipType, AnnualFee, JoiningFee from MembershipCategory"
Dim cmd As New SqlCommand(cmdString, conn)
da.SelectCommand = cmd
Dim ds As New DataSet
da.Fill(ds, "MembershipCategory")
conn.Close()
connString = "data source=RUATHA\SQLEXPRESS;Initial
Catalog=WOSAdmin;Integrated Security=True"
conn.ConnectionString = connString
conn.Open()
Dim cmd1 As New SqlCommand(cmdString, conn)
Dim da1 As New SqlDataAdapter(cmd1)
Dim builder As New SqlCommandBuilder(da1)
da1.InsertCommand = builder.GetInsertCommand
da1.DeleteCommand = builder.GetDeleteCommand
da1.UpdateCommand = builder.GetUpdateCommand
Dim ds1 As New DataSet
da.Fill(ds1, "MembershipCategory")
ds1.Merge(ds) ' I have used Copy, but makes no difference
' In both cases ds1 contains the data from ds
da.Update(ds1, "MembershipCategory")
table in another database.
The first table (WOS) contains 11 records, the second (WOSAdmin) is
empty.
The problem is that the data is never inserted into the second table.
Can anyone explain what I am doing wrong?
Definitions of the tables and the code I am using below:
USE [WOS]
GO
/****** Object: Table [dbo].[MembershipCategory] Script Date:
01/21/2006 21:48:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MembershipCategory](
[TypeOfMember] [smallint] NOT NULL,
[MembershipType] [nvarchar](50) COLLATE Latin1_General_CI_AS
NULL,
[AnnualFee] [money] NULL,
[JoiningFee] [money] NULL,
CONSTRAINT [PK_MembershipCategory] PRIMARY KEY CLUSTERED
(
[TypeOfMember] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
USE [WOSAdmin]
GO
/****** Object: Table [dbo].[MembershipCategory] Script Date:
01/21/2006 21:47:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MembershipCategory](
[TypeOfMember] [smallint] NOT NULL,
[MembershipType] [nvarchar](50) COLLATE Latin1_General_CI_AS
NULL,
[AnnualFee] [money] NULL,
[JoiningFee] [money] NULL,
CONSTRAINT [PK_MembershipCategory] PRIMARY KEY CLUSTERED
(
[TypeOfMember] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Dim conn As New SqlConnection
Dim da As New SqlDataAdapter
Dim connString As String = "data
source=RUATHA\SQLEXPRESS;Initial Catalog=WOS;Integrated Security=True"
conn.ConnectionString = connString
conn.Open()
Dim cmdString As String = "select TypeOfMember,
MembershipType, AnnualFee, JoiningFee from MembershipCategory"
Dim cmd As New SqlCommand(cmdString, conn)
da.SelectCommand = cmd
Dim ds As New DataSet
da.Fill(ds, "MembershipCategory")
conn.Close()
connString = "data source=RUATHA\SQLEXPRESS;Initial
Catalog=WOSAdmin;Integrated Security=True"
conn.ConnectionString = connString
conn.Open()
Dim cmd1 As New SqlCommand(cmdString, conn)
Dim da1 As New SqlDataAdapter(cmd1)
Dim builder As New SqlCommandBuilder(da1)
da1.InsertCommand = builder.GetInsertCommand
da1.DeleteCommand = builder.GetDeleteCommand
da1.UpdateCommand = builder.GetUpdateCommand
Dim ds1 As New DataSet
da.Fill(ds1, "MembershipCategory")
ds1.Merge(ds) ' I have used Copy, but makes no difference
' In both cases ds1 contains the data from ds
da.Update(ds1, "MembershipCategory")