0

Hello everyone, can you help?

I am trying to build a site using visual studio with a access database back end, basically two of the tables in the database are linked and I want to update the both of them at the same time.

What I have is a "Formview" data connection where three of the input boxes link to a "Names" table and one input box links to the "Group" table. I want to insert data into both tables on the same button click.

When I try though I can't seem to get this to work, I thought you could put a standard INSERT query in the code referencing the two tables as below

INSERT INTO Names (person1, Address, Postcode)
VALUES (@person1, @Address, @Postcode) AND
INSERT INTO Group (GroupName)
VALUES (@GroupName)

I keep getting a error about inserting a ";" at the end but tried that and nothing works.

Does anyone have any thoughts at all? Am I missing something obvious?

Thanks

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by kameswari
0

Hi you can write two seperate insert queries on single button click... y r u opting for single query.. if u need that let me know.. please follow this..

INSERT INTO Names (person1, Address, Postcode)
VALUES (@person1, @Address, @Postcode)  //this is first query

INSERT INTO Group (GroupName)
VALUES (@GroupName)
//this is second query...

just split your query...

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

0

I don't think it is possible to run multiple queries in a single transaction with access. You have to split it out to two commands in code.

0

Hi you can write two seperate insert queries on single button click... y r u opting for single query.. if u need that let me know.. please follow this..

INSERT INTO Names (person1, Address, Postcode)
VALUES (@person1, @Address, @Postcode) //this is first query

INSERT INTO Group (GroupName)
VALUES (@GroupName)
//this is second query...

just split your query...

Hello, thanks for reply

This is my code

<asp:SqlDataSource ID="AdminDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:itAlertsDatabaseConnectionString %>"
 
InsertCommand="INSERT INTO SMS_GroupRecipients (emailaddress, mobilenumber, Name) VALUES (@emailaddress, @mobilenumber, @Name) INSERT INTO SMS_GroupNames (GroupName) VALUES (@GroupName)" 
                                
ProviderName=<%$ConnectionStrings:itAlertsDatabaseConnectionString.ProviderName %>" 
                                
SelectCommand="SELECT SMS_GroupRecipients.*, SMS_GroupNames.* FROM SMS_GroupRecipients, SMS_GroupNames">
</asp:SqlDataSource>

But I'm still getting the error about the ";" sorry any thoughts?

0

Sknake is right!! Two separate insert statements is required

Hello! Have I not done two seperates ones as shown above?

0

Hi...
You have written continuous query.. splitting means... You need to take 2 seperate insert queries... please dont concatenate them...

hope you understand..

Best Regards,
Kameswari Chavali

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.