KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Summary I'm currently writing an application where I have located my SQL instructions into a project's parameters. Within the code, I get the value of my query which returns the query itself. Let's for instance say that my SQL query is like so: select col1, col2, col3 from my_table Besides, col1 , col2 and col3 are from different tables and are migrated as foreign key into my_table. So, when it comes to the insert, I have to perform multiple INSERT statements to get the values from the other tables for these above-mentioned columns. Let's say as follows: BEGIN TRANSACTION insert into first_table (col_x, col_y) values ('col_x', 'col_y') insert into second_table (col_z, col_a) values ('col_z', 'col_a') insert into third_table (col_b, col_c) values ('col_b', 'col_c') and finally: insert into my_table (col1, col2, col3, col_v) values (@col1, @col2, @col3, 'col_v') COMMIT Take it that these col1 , col2 , col3 columns are auto-increment integers for tables first , second and third . Questions Could I write a complex SQL statement into the IDbCommand.CommandText property while each instruction would be separated by a semicolon ( ; )? Is it possible to include a BEGIN TRANSACTION...COMMIT/ROLLBACK into this CommandText property? In short, could I write something like this? Using cnx = New SqlConnection(connString) Using cmd = cnx.CreateCommand() cmd.CommandText = "BEGIN TRANSACTION " _ & "insert into first_table (col_x, col_y) values ('col_x', 'col_y');" _ & "insert into second_table (col_
Tags (comma-separated)
Save Edits
Cancel