Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: Insert data from Table 1 to Table 2


Message #1 by "Jennifer Moore" <tinfox@o...> on Tue, 11 Feb 2003 14:48:12 +0800
    
   I am trying to pull up a dataset from one table and insert the data into another table, adding new rows to that table(table 2). 
Here are the 2 insert statements that I have:
 
INSERT INTO CurrentTable ( TableID, ColumnName, PayColumn,
Column3 ) SELECT ( SELECT COUNT(*) + (SELECT
MAX(TableID) FROM Table t1) FROM Table t2 WHERE
t2.table = Table.Table ) AS [TableId], Table, [Pay Table], 0
FROM Table
 
or
 
Dim InsertCommand As New SqlCommand("Insert Into [Table2] ([Table1].[columnid]) Values (@table2columnid)", myConnection)
        sqlCommand.Parameters.Add("@table2columnid", System.Data.SqlDbType.VarChar).Value = table2columnid
 
obviously neither work, anyone have any ideas???
 
TiNFoX 
-- 
_______________________________________________
http://www.operamail.com
Now with OperaMail Premium for only US$29.99/yr

Powered by Outblaze
Message #2 by "Kevin Ayers" <kevin@f...> on Tue, 11 Feb 2003 12:00:28 -0500
The SQL statement is incorrect.  If you are using a select statment with the
insert than you do not use 'into' .  Check out the SQL Server books
online -> search for insert and review the syntax for the command if you
need any additional info.

Kevin

----- Original Message -----
From: "Jennifer Moore" <tinfox@o...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Tuesday, February 11, 2003 1:48 AM
Subject: [ado_dotnet] Insert data from Table 1 to Table 2


>
>    I am trying to pull up a dataset from one table and insert the data
into another table, adding new rows to that table(table 2).  Here are the 2
insert statements that I have:
>
> INSERT INTO CurrentTable ( TableID, ColumnName, PayColumn,
> Column3 ) SELECT ( SELECT COUNT(*) + (SELECT
> MAX(TableID) FROM Table t1) FROM Table t2 WHERE
> t2.table = Table.Table ) AS [TableId], Table, [Pay Table], 0
> FROM Table
>
> or
>
> Dim InsertCommand As New SqlCommand("Insert Into [Table2]
([Table1].[columnid]) Values (@table2columnid)", myConnection)
>         sqlCommand.Parameters.Add("@table2columnid",
System.Data.SqlDbType.VarChar).Value = table2columnid
>
> obviously neither work, anyone have any ideas???
>
> TiNFoX
> --
> _______________________________________________
> http://www.operamail.com
> Now with OperaMail Premium for only US$29.99/yr
>
> Powered by Outblaze
>
> ===
> Fast Track ADO.NET with C# is a concise introduction to the concepts,
techniques, and libraries that you will need in order to start using ADO.NET
in your applications. The book covers DataSets and Typed DataSets, accessing
data using DataReaders and DataAdaptors, the close relationship between
ADO.NET and XML, how and where to use ADO.NET in your enterprise
applications, and how to use Web Services and ADO.NET to easily pass data
between applications.
> http://www.wrox.com/books/1861007604.htm


  Return to Index