Click here to Skip to main content
Sign Up to vote bad
good
See more: SQLOracleVB.NET
I am working on a vb application that runs sql scripts/commands/queries that are input by the user. It works fine for all single commands, but does not work if the user enters multiple commands at once, which is highly likely to happen with the use of the application. Fro example the text could be:
   INSERT INTO someTable(col1, col2, col3) VALUES (v1, v2, v3);
   INSERT INTO somaTable(col1, col2, col3) VALUES (v4, v5, v6);
and when the OracleCommand.ExecuteNonQuery is run it gets an error of invalid character (the ";"). Or if the user tries to create multiple procedures like:
  create or replace
  PROCEDURE owner.someprocedure
  ()
  Is
  BEGIN
  ...
  END;
 
  /
  
  create or replace 
  PROCEDURE owner.someprocedure2
  ()
  IS
  BEGIN
  ...
  END;
It will create the first procedure as:
create or replace
  PROCEDURE someprocedure
  ()
  IS
  BEGIN
  ...
  END;
 
  /
 
  create or replace 
  PROCEDURE owner.someprocedure2
  ()
  IS
  BEGIN
  ...
  END;
instead of two individual procedures. So how do I let the OracleCommand know that there are multiple commands/queries/scripts to be run?
 
Thank you in advance.
Posted 25 Sep '12 - 8:33
ddrake2262
Edited 25 Sep '12 - 8:38

Comments
Maciej Los - 25 Sep '12 - 15:14
Probably, you need to loop through the commands.
digimanus - 25 Sep '12 - 17:30
which driver do you use?
ddrake2 - 25 Sep '12 - 18:24
I'm new to this, you will have to be a little more specific with the question.
digimanus - 26 Sep '12 - 6:57
in your connectionstring a provider can be entered. Which one do you use?
digimanus - 27 Sep '12 - 9:24
also: read about ADO and MARS (Multiple Active Result Sets)

2 solutions

1. u should use loop inside stored procedure
2.firstly send multiple rows in single string and split string in procedure
or u can use table type variable
u should try like this
 
CREATE PROCEDURE [dbo].[spHRSaveSkillsDtls]
/**************************************************************************************************************
 

 
EXEC spHRSaveSkillsDtls @CandidateID=1,@SkillsDtls='0±1±P±1±1±$123±10±S±1±$124±12±P±1$'
***********************************************************************/
@CandidateID VARCHAR(20),
@SkillsDtls VARCHAR(5000)
 
AS
BEGIN
DECLARE
@len INT,@pos1 INT,@pos2 INT,@pos3 INT,@pos4 INT,@pos5 INT,@i INT,@row VARCHAR(50),@rowpos INT,@temp INT,
@SkillsDtlsID INT,@SkillsID SMALLINT,@SkillsType VARCHAR(10),@Active TINYINT,@DisOrder TINYINT
SET @len=LEN(@SkillsDtls)
SET @i=1
SET @temp=0

WHILE(@i<@len)
BEGIN
SET @rowpos=CHARINDEX('$',@SkillsDtls,@i)
SET @row=SUBSTRING(@SkillsDtls,@i,@rowpos-@temp-1)
SET @Pos1=CHARINDEX('±',@row,1)
SET @SkillsDtlsID= SUBSTRING(@row,1,@pos1-1)
SET @pos2=CHARINDEX('±',@row,@pos1+1)
SET @SkillsID =SUBSTRING(@row,@pos1+1,@pos2-@pos1-1)
SET @pos3=CHARINDEX('±',@row,@pos2+1)
SET @SkillsType=SUBSTRING(@row,@pos2+1,@pos3-@pos2-1)
SET @pos4=CHARINDEX('±',@row,@pos3+1)
SET @Active=SUBSTRING(@row,@pos3+1,@pos4-@pos3-1)
SET @pos5=CHARINDEX('±',@row,@pos4+1)
SET @DisOrder=SUBSTRING(@row,@pos4+1,@pos5-@pos4-1)

SELECT @pos1=0,@pos2=0,@pos3=0,@pos4=0,@pos5=0
SET @i=@rowpos+1
SET @temp=@rowpos
SET @row=null
IF(@SkillsDtlsID=0)
BEGIN
--SET @DisOrder=(SELECT MAX(@DisOrder )FROM tbHRCandidateSkillsDtls)
--SET @DisOrder=@DisOrder+1
INSERT INTO tbHRCandidateSkillsDtls(CandidateID,SkillsID,SkillsType,Active,DisOrder)
VALUES(@CandidateID,@SkillsID,@SkillsType,@Active,@DisOrder)
END
ELSE
BEGIN
UPDATE tbHRCandidateSkillsDtls SET CandidateID=@CandidateID,SkillsID=@SkillsID,SkillsType=@SkillsType,Active=@Active
WHERE SkillsDtlsID=@SkillsDtlsID
END
END
END
  Permalink  
you where close in your search. Look here[^].
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 464
1 Mahesh Bailwal 373
2 Maciej Los 215
3 CPallini 175
4 Aarti Meswania 173
0 Sergey Alexandrovich Kryukov 9,417
1 OriginalGriff 7,204
2 CPallini 3,933
3 Rohan Leuva 3,211
4 Maciej Los 2,743


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid