Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2009, 06:37 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

Now i have stumbeld into onother problem, i need to insert into 2 tables at the same time the same data.

Code:
Dim con AsNew SqlConnection(ConfigurationManager.ConnectionStrings("test").ConnectionString)
Dim cmdd AsNew SqlCommand("INSERT INTO " & l & " Campaign(Template, CampaignName) VALUES(@Template, @CampaignName)", con)
cmdd.Parameters.Add("@Template", Data.SqlDbType.VarChar, 50).Value = Me.ListBox1.SelectedValue
cmdd.Parameters.Add("@CampaignName", Data.SqlDbType.VarChar, 50).Value = s
 
con.Open()
cmdd.ExecuteNonQuery()
con.Close()
" & l & " is table 1 when i try to run the statement i get
Incorrect syntax near 'Campaign'.
__________________
bx
 
Old January 15th, 2009, 08:06 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default I believe...

You issues is due to your table being named Table 1 instead of Table1 or Table_1

you can't have a space in the name because the server will see it as if you want to represent the table as 1

so it would be 1.campaign which still won't work because your table name is Table 1 not Table.

I hope this makes sense. just rename the table to Table1 or Table_1
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old January 15th, 2009, 08:52 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

I know that spaces are not wellcomed in sql but that is not the isue,
i dont know what goes betwin the tables?
ex
INSERT INTO Table1 Campaign(Template, CampaignName) VALUES(@Template, @CampaignName)", con

and i have to use " & l & " cos that is what makes Table 1 into Table1
__________________
bx
 
Old January 15th, 2009, 06:41 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You can *NOT* insert into two tables with a single SQL statement.

Period. End. Done.

You MUST use two SEPARATE queries.

And Jason (Alliance) is wrong: You *CAN* have a space in a table name. You just have to "escape" the name in your SQL, as for example
INSERT INTO "Table 1" ...
(assuming you use the default meaning of quotes in SQL Server 2005 and 2008)
or maybe
INSERT INTO [Table 1] ...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search in Database????? Samora C# 2 October 10th, 2007 07:41 AM
how to search in database saif44 ASP.NET 2.0 Professional 11 March 8th, 2006 03:33 PM
database search rajuru PHP Databases 2 November 9th, 2004 04:32 PM
Search Database bspradeep Classic ASP Databases 1 September 15th, 2004 05:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.