SQL Parameter
How do u setup SQL parameter in .NET OLEDataAdapter. I tried to follow .NET sample to use ? but it doesn't work. Any idea? TIA
If you want to select all items you should use a query without a WHERE clause:
Select Id from table1
Please refer to the following page for more information about how to add a new query to your table adapter:
https://msdn.microsoft.com/en-us/library/kda44dwy.aspx.
You could call the new method with the new query "FillAll" or something.
You cannot select all values by passing some magic parameter value to the FillBy_Id query since it takes an id value to filter on.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't post several questions in the same thread.
Similar Messages
-
Sql parameter substitution problems
Hi,
I am having problems with the sql parameter substitution. I have a query that
looks like this:
select name,value from table where name in ('name1','name2');
I have tried building a string that equals "'name1','name2'" and passing it as
a parameter to sql entering the javaDoc comments like:
select name,value from table where name in ({nameString})
The problem is that when it is substituted and set to the database it looks like
this:
select name,value from table where name in ('\'name1\',\'name2\'');
This will not work. Does anyone have any suggestions on how to do this using a
database control. Basically I'm looking for the ability to create dynamic sql
statements.
Thanks for your help.
Regards,
JamesAnurag,
Thanks for the reply. I don't think that this solves my problem though. I will
never know how many strings to pass. It's all based on what the user wants, they
could ask for 2, 20, or any other number of names. It sounds like using a Database
control is not really possible for this situation. What do you think? Any chance
of this making into workshop in the future or in these situations is creating
an EJB the only way to go?
Thanks again.
Regards,
James Chamberlain
"Anurag Pareek" <[email protected]> wrote:
Hi James,
This result is same as what you will get on executing the following prepared
statement:
conn.prepareStatement("select empid from empdemo where name in (?)");
pstmt.setString(1,"'Person 1','Person 2','Person 3'");
pstmt3.execute();
Workshop's DBControl internally uses a PreparedStatement, hence you would
obtain the same result.
To get it working, you will need to pass in the 3 strings separately
as
below:
conn.prepareStatement("select empid from empdemo where name in
pstmt.setString(1,"Person 1");
pstmt.setString(1,"Person 2");
pstmt.setString(1,"Person 3");
Please do let me know if you have further queries regarding the issue.
Regards,
Anurag
Workshop Support
"James Chamberlain" <[email protected]> wrote in message
news:[email protected]...
Hi,
I am having problems with the sql parameter substitution. I have aquery
that
looks like this:
select name,value from table where name in ('name1','name2');
I have tried building a string that equals "'name1','name2'" and passingit as
a parameter to sql entering the javaDoc comments like:
select name,value from table where name in ({nameString})
The problem is that when it is substituted and set to the databaseit
looks like
this:
select name,value from table where name in ('\'name1\',\'name2\'');
This will not work. Does anyone have any suggestions on how to do thisusing a
database control. Basically I'm looking for the ability to create dynamicsql
statements.
Thanks for your help.
Regards,
James -
I'm not sure if this is a CR or BOE question but I'll post here first.
Is there any way to change the parameter order of a SQL Command Parameter?
I know it usually goes by the alphabetical order of the parameter name (i.e.: SQL Parameter name "StartDate" and "EndDate" would actually prompt EndDate first then StartDate).
I guess I can easily try to change the wording of the parameter names and that's what I did (I changed it to "1StartDate" and "2EndDate"). It prompts correctly in CR when I preview it... but when I bring it up to BOE and run the report there, it will prompt me the 2EndDate first instead of 1StartDate.
Any ideas?James,
I have changed appropriately to match alphabetically (eg. Begin & End)... and like always, Crystal will display the prompt correctly and in correct when refreshing the report. But once I bring it up on BOE, it will prompt for End first then Begin.
Brian,
Thanks for your suggestion. However, I am aware of the parameter orders in the parameter viewer. While the parameter order list applies to parameter used on the actual report, it does not apply to the order SQL Command Parameters are for some reason. Regardless, it has always been set in the order I'd like it... just that when it comes to the SQL Parameter part, it never follows.
Could this be a BOE issue then? -
Pl/sql parameter portlet - need some help/advice - how to create
I want to create a pl/sql portlet that accepts a parameter and on submit passes the parameter to other portlets (sql reports) these are then automatically run to display the new data.
E.g.
parameter portlet = deptno
On submit
Sql reports then refreshed using the parameter
I am aware, and have tried the mycompnay demo, which works exactly as I want but the parameter portlet cannot be amended and is written in Java.
I need a pl/sql equivalent so I can tailor the code.
Any advice examples or guidance would be really appreciated.
Thanks in anticipation.
SDHi,
You can use a form portlet to accept parameters and then call a report in the success procedure of the form. In this example it calls a report with the value in the flightno field.
declare
flightno number;
blk varchar2(10) := 'DEFAULT';
begin
flightno := p_session.get_value_as_varchar2(
p_block_name => blk,
p_attribute_name => 'A_FLIGHT_NO');
call('SJDEMO30.report1.show?p_arg_names=flightno&p_arg_values='||
flightno);
end;
Thanks,
Sharmila -
I am using the database connectivity (ADO based) tool and I want to be able to insert a null values.
I have included a simple VI that demonstrates how this works with SQL toolkit .
Null values are very useful and occur frequently in dealing with data. I wish that LabVIEW handled them much better - (e.g. there is not datatype in LabVIEW corresponding to a Null value).The VI was not attached but I'm going to answer with what I have here.
- Currently, the Database Toolset converts NULLs to the default value for LabVIEW data types (ie, False for Boolean, empty strings, zero for numbers, empty arrays, etc). In the user manual there is an example that shows database records containing NULL values being first converted to a string, empty strings (the NULLs) are then converted to NaNs instead of the usual zero value. This method requires you to know what data types each field contains and that they know what to look for and how to convert the data.
You can go to this following link to suggest that a null datatype be implemented:
https://sine.ni.com/apps/we/nicc.call_me?p_country=&p_lang_id=US&p_form_id=58
-Also you cannot leave par
ameters values empty because there is a big difference between executing an SQL statement and doing a Parameterized Query, especially when looking at the low-level ADO layer.When doing Parameterized Queries, you MUST specify all parameter values - leaving them empty results in ADO trapping errors rather than using a default value.
Regards,
Cyril Bouton
Applications Engineer
National Instruments
Cyril Bouton
Active LabVIEW Developper -
Putting an Apostrophe in an SQL Parameter
Anyone know how to escape an apostrophe for passing to an XSQL page?
I'm making an online directory. I get a list of names from the table, and then the user can click on a name to get more information. I'm having a real problem with names that contain aprostophies (ex: O'Donald)
If I simply call my XSQL page with the name as normal, it gives me an SQL error because there is a single apostrophe in my query. I've attempted to escape the apostrophe in my XSL file, but it gives me a Literal Mismatch error when I try to look for it using '
Here is the code I'm trying:
<xsl:template match="name">
<a><xsl:attribute name="href">search.xsql?name=<xsl:value-of select="substring-before(../name,''')" />''<xsl:value-of select="substring-after(../name,''')" /></xsl:attribute><xsl:value-of select="." /></a>
I've also tried making a variable that contains a '. Doing that, I don't get an error, but the substring-before return nothing... Thanks for any help you can offer!1/ Would you try to put the aprostophies there without escaping ?
2/ Use XSLT extension -
Hell,<br /><br />After I write pdf form, when I clicked the <submit button> in pdf form, I want to save data to MS SQL SERVER.<br /><br />I use Adobe Livecycle desinger v.8.1 program.<br /><br />My question is,<br />1. How to query with <where> statment <br /> ex) SELECT * FROM pubs WHERE title_id = '<param>'<br /><br />2. How to save to MS SQL SERVER<br /> ex) INSERT INTO pubs VALUES ('<param1>','<param2>',...)<br /><br />Thanks for any help that you can give!
A warning which I hope is appropriate... even if you have taken care
of this, it may help other people who read this. The code you have
written will leave your SQL server wide open to attacks of the kind
which have compromised many web sites recently, so your server can be
used for sending spam, collecting passwords, stealing credit card
details etc.
Be sure you know what "SQL injection" is. You MUST check in detail all
of the data that you insert into an SQL command, even simple SELECT
statements, or you can be attacked. See the Wikipedia entry on SQL
Injection to get started.
Aandi Inston -
PL/SQL Web Service altered method names
Using JDev 10.1.3 production, creating a web service from a PL/.SQL procedure results in 3 names for the service. Why is this? Will it change in a future release?
PL/SQL parameter list:
procedure calc_slots(pdrive in out varchar2,
pName in varchar2,
pfunc in number,
pstart in date,
pend in date,
pwbslots in number,
pbkst in date,
pbkend in date,
pOutval out varchar2,
pautoequip in number := 0,
pautoslots in number := 0) is
Method 1:
calcSlots
parameters
xsd:string pdrive_inout =
xsd:string pname =
xsd:decimal pfunc =
xsd:dateTime pstart =
xsd:dateTime pend =
xsd:decimal pwbslots =
xsd:dateTime pbkst =
xsd:dateTime pbkend =
Method2:
calcSlotsvSSBTTBTTSB
parameters
xsd:string pdrive_inout =
xsd:string pname =
xsd:decimal pfunc =
xsd:dateTime pstart =
xsd:dateTime pend =
xsd:decimal pwbslots =
xsd:dateTime pbkst =
xsd:dateTime pbkend =
xsd:decimal pautoequip =
Method3:
calcSlotsvSSBTTBTTSBB
[parameters
xsd:string pdrive_inout =
xsd:string pname =
xsd:decimal pfunc =
xsd:dateTime pstart =
xsd:dateTime pend =
xsd:decimal pwbslots =
xsd:dateTime pbkst =
xsd:dateTime pbkend =
xsd:decimal pautoequip =
xsd:decimal pautoslots =
}Yes, we tried with databse adapter with out any problem. we want specifically with the PL/SQL Web service using the web service wizard.
Thanks in advance. -
Use of Input Variables in SQL-Queries Sometimes Not Possible
Only in simple SELECT-statements the use of input variables ([%0], [%1], etc.) work without problems.
In more complex queries the use of these variables is not possible (e.g. SELECT-statements with sub-queries, sometimes when UNION is used - but I couldn't find any general rule when the problems will arise; sometimes two different queries with the same query-structure behave in different ways when these variables are used).
In these cases the query is not executed - not even the input-window to enter values into the input variables is displayed. The query stops with some strange error-messages in the status line. These error-messages doesn't have any relation to the actual query - sometimes it refers to field-names never used in the query or refers to syntax error which do not exist.
If the input variables are replaced by constant values there are no problems so there can't be any syntax errors - the only difference is the presence or absence of input variables.
Example:
provided that the queries have a certain complexity
SELECT ...
FROM ... OINV Tx ...
WHERE ... Tx.DocDate >= [%0] ...
does not work,
SELECT ...
FROM ... OINV Tx ...
WHERE ... Tx.DocDate >= '1.1.2007' ...
works!
Does anybody have run into the same problem and now if it is a bug of SAP-BO or an error on behalf of the user? Does anybody know a way to correct the problem?
Thanks in advance!
Frank
By the way: Are there any rules where exactly input variables can be used in a query?
Only in SELECT-statements? Where there exactly?
In statements outside of SELECT?Only SAP Partners Can access service.sap.com/notes, but I think it is possible to search in them from the customer portal as well.
Here are summary of the two notes mentioned before this:
730960:
<i>
The following query is an example for how to define variables in long
queries rather than using "Fixed Declares".
You need to use exactly the same template as follows, do not delete
"comments" from this query.
The only changes you need to do :
1. In the first and in the fifth rows you need to select the table to which you would like to relate the variable e.g. in this example, the variable is related to the table VPM1 - 'Payments to Vendors - Rows'.
2. In the fourth and in the eighth rows you need to select the field to which you would like to define the variables e.g. in this example, the variable is the field 'DueDate'.
/SELECT FROM [dbo].[VPM1] T0/
declare @fromdate as datetime
/* WHERE */
set @fromdate = /* T0.DueDate */ '[%0]'
/SELECT FROM [dbo].[VPM1] T1/
declare @tilldate as datetime
/* WHERE */
set @tilldate = /* T0.DueDate */ '[%1]'
select OVPM.docnum, VPM1.dueDate,VPM1.CheckNum, VPM1.Branch,
VPM1.BankCode, VPM1.CheckSum, OVPM.CardName,
case
when OPCH.docnum is null then VPM2.docEntry
else OPCH.docnum
end as 'docnum'
from OVPM INNER join VPM1 on OVPM.docnum = VPM1.docnum
left join VPM2 LEFT JOIN OPCH ON VPM2.DocEntry = OPCH.DocEntry
on OVPM.docnum = VPM2.docnum
where OVPM.Canceled = 'N' AND VPM1.DueDate >=@fromdate AND
VPM1.DueDate <=@tilldate
</i>
955295:
<i>
Using SAP Business One Survey Variables (parameters) in a 'Set' SQL Statement can give an error in the Query Generator.
For Example:
Declare @Num as numeric(2)
Set @Num = [%0]
Select T0.DocNum
From ORDR T0
Where DocNum = @Num
Other terms
query, SQL, parameter, survey, variable, query generator, set, declare, [%0], table, error, SAP Business One
Reason and Prerequisites
FAQ
Solution
In such cases you need to put in an SQL remark statement a reference field in the DB for the Survey Variable (any field).
For Example: (to make the above query work)
Declare @Num as numeric(2)
Set @Num = /* T0.DocNum */ [%0]
Select T0.DocNum
From ORDR T0
Where docnum = @Num
</i> -
How to assign the parameter in case condition?
Dear All,
I have one procedure say p1. I want to pass one parameter like d_forcd = 'IN' and ALC_Code in ('11', '21', '31') from this procedure.
In begin part I have one query. Can I pass this paramer in case condition in that query.
If possible please hint me.
Thanks in advance,
Prathamesh.
[pre]There is probably a way using CASE, but it seems easier without:
SQL> var param varchar2(10)
SQL>
SQL> exec :param := 'IN'
PL/SQL procedure successfully completed.
PARAM
IN
SQL> SELECT * FROM dual
2 WHERE ( :param = 'IN' AND dummy IN ('A','B','X','Y')
3 OR NVL(:param,'?') != 'IN' );
D
X
1 row selected.Substitute your actual PL/SQL parameter for the SQL*Plus variable. -
How to do a like parameter in a databinding to a table
I have a simple two page sample, where on the first page I have a text box. I want to take the text from this text box and do a LIKE conditional in my sql where clause. Here is how I am trying to set the sql parameter but I get an sql error java.sql.SQLException: [sunm][SQLServer JDBC Driver]Invalid parameter binding(s).
getSessionBean1().getPatchesRowSet2().setObject(
1, patchName.getText());
I even tried
getSessionBean1().getPatchesRowSet2().setObject(
1, "%"+patchName.getText()+"%");
but got the same errorStill not luck, still getting Invalid parameter bindings error
here is my try block and the two things suggested I have tried without success. The column patch is a varchar(255) in MSSQL
try
tmpStr = "case3";
log("%"+patchName.getValue().toString()+"%");
/*getSessionBean1().getPatchesRowSet2().setObject(
1,"%"+patchName.getValue().toString()+"%");
command="select * from patches where patch like '%"
+ patchName.getValue().toString()
+ "%'";
getSessionBean1().getPatchesRowSet2().setCommand(command);
//getSessionBean1().getPatchesRowSet2().execute();
//patchesDataProvider2.refresh();
catch (Exception e)
log("Stack Dump:[[["+e+"]]]");
Here is the error message on the web browser
Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.
Exception Details: org.apache.jasper.JasperException
java.sql.SQLException: [sunm][SQLServer JDBC Driver]Invalid parameter binding(s).
Possible Source of Error:
Class Name: org.apache.jasper.servlet.JspServletWrapper
File Name: JspServletWrapper.java
Method Name: service
Line Number: 384
Source not available. Information regarding the location of the exception can be identified using the exception stack trace below. -
Scripting pl/sql from unix
I am wondering if there is a way to do this with certain restrictions. If not, I can do it another way.
1. I have a list of values in a unix .txt file of the form
VALUEA
VALUEB
VALUEC
I know how to read a list in unix using a loop.
2. I want to call a pl/sql anonymous block that I have in a .sql file 1 time for every value in this script and pass the value.
I do know how to read a value and then pass it to a pl/sql parameter and then call the pl/sql parameter.
What I don't know how to do is
Do this with only logging into sqlplus one time. I dont want to do the following
unix runs in a loop
reads 1 record from file
logs into sqlplus
runs the procedure and passes the value
log out of sqlplus
end loop
I want to
1. read all the values from the file
2. store it somehow in memory (variable of some sort)
3. pass this value to the pl/sql procedure
I do not want to make any objects in the database such as a global temporary table.
Yes I can actually do this, but wondering if it is possible to avoid. Makes it easier to deploy to alot of different databases. If I have to make a database object, then i have to make an object in alot of databases. If I can run it all from unix, all I have to do is change the target and the password. So it is easier to deploy.I don't need to put this in an Oracle Directory. I am not calling anything from pl/sql stored in the database. It is going to all be done with unix scripts and anonymous block sql in .sql statements in the OS. This allows me to take advantage of clustered storage (I can have alot of databases servers mounted on 1 directory). So the unix script will log into oracle and call the .sql script.
I can build the pl/sql dynamically. I'd rather not do that. The thing is I have alot of databases I want to deploy code to. So I am trying to come up with a pattern I can follow. So if I add a new database or what to deploy somewhere else, I can just use add a line to a file.
Adding database objects every time I need to deploy to a new database is a pain. It is far more scaleable to handle all of this in unix.
Edited by: Guess2 on Jan 12, 2010 7:43 AM -
Error using SQL data in javascript vars
I have a javascript routine which queries sqlite for a series
of top-level categories, then, for each category, executes another
query, using an item ID which is a result of the first query as
follows:
// Get first level of categories table
var stmt = new air.SQLStatement();
stmt.sqlConnection = conn;
stmt.text = "SELECT * FROM categories WHERE childOf IS NULL
ORDER BY Name";
stmt.execute();
var result = stmt.getResult();
var numResults = result.data.length;
for (i = 0; i < numResults; i++) {
var item = result.data
air.trace('Cat: '+item.Name);
// Get sub-level categories
var stmt2 = new air.SQLStatement();
stmt2.sqlConnection = conn;
stmt2.text = "SELECT * FROM categories WHERE childOf =
:itemID";
stmt2.parameters[":itemID"] = item.ID;
stmt2.execute();
var result2 = stmt2.getResult();
var numResults2 = result2.data.length;
for (j = 0; j < numResults2; j++) {
var inner = result2.data[j];
air.trace('Cat: '+item.Name);
The problem is, when I try to assign the value of item.ID to
the SQL parameter in the statement:
stmt2.parameters[":itemID"] = item.ID;
It outputs the error: "TypeError: Null value"
I can print the value of item.ID to the screen, or write it
to the terminal with air.trace and see the value fine, but when I
try to assign it as an sql statement parameter, it gives the error.
If I manually assign item.ID a value, the statements work
fine. If I put a fixed value in instead of the variable
substitution, it also works fine. Only when I try to use the result
of the first SQL query in a second SQL query does it fail with this
error.
Can anybody please explain why ?Thanks for the suggestion jasowill, but unfortunately this
doesn't fix the problem.
I can assign the data to a temporary variable and then print
that variable and everything LOOKS right, but again, it still can't
be used as an sql parameter. I've also tried tactics such as
subtracting zero from the value to convert the type from string to
integer but again, no luck.
What it comes down to is; the value of the variable looks
fine when you print it to the screen or write it to the console
with trace, but using it as an sql parameter gives a TypeError
every time. It's as though the data is in some weird foreign type
or something.
In response to enorton, yes I am using:
var item = result.data (square bracket) i (square bracket)
but the forums are filtering this bit of the code out as I
believe it is an italic code. As you can see, in the second
variable assignment, it uses [j] in the same way as you would
expect.
Yes, the database is generated by AIR. I'm not at home so I
don't have access to paste my create statements, but fwiw, the
field in question is an INT. I know the SQL is not at fault though,
as if I manually assign a value like so:
stmt2.parameters[":itemID"] = 5;
it works fine. Also, manually assigning a value to item.ID
like so:
item.ID = 5;
stmt2.parameters[":itemID"] = item.ID;
also works fine. It's only when the value of item.ID has been
pulled from SQL prior does it generate this TypeError.
Really appreciate the comments and assistance ! -
Hi
For performance and security reasons it is usually better to use SQL-Parameters (like :1) in SQL-Queries instead of building the SQL-String directly. I'd like to adopt this best practice but stumbled over a problem: BC4J adds Parameters when applying View-Links. Unfortunately I've no control over the Parameter added. See the following example:
Assume you have a View-Object with the following Query:
select NAME from USERS where NAME like :1
:1 is my custom parameter which I'd like to set using method 'setWhereClauseParams'. This view works fine until this view is used as a detail of a view link. In this case BC4J adds his own SQL-Parameter so that the query looks like that:
select NAME from USERS where NAME like :1 and (users.USR_ID = :1)
where the first :1 is my own Parameter and the second :1 is added by BC4J as part of the view link. This certainly does not work.
Can anyone give me a hint how to use SQL-Parameters correctly in BC4J-Views? Is there a "How To"-Document or something like that which explain how to use SQL-Parameters in BC4J?
Any hints are appreciated
Thanks
Frank BrandstetterThis way framework automatically adds the new where clause to the existing one, thus eliminating your issueDoes it? I'm not sure! I just tried it out the following example:
Master ViewObject: GroupsView
Detail ViewObject: UsersView (ViewLink to GroupsView)
GroupsViewImpl GrpVo = getGroupsView();
GrpVo.first();
UsersViewImpl UsrVo = getUsersView();
UsrVo.setWhereClause("NAME like :1");
System.out.println("Query=" + UsrVo.getQuery());This code prints:Query=SELECT Users.USR_ID,Users.GRP_ID,Users.NAME FROM USERS Users WHERE (NAME like :1) AND Users.GRP_ID = :1This does not look as if my issue is solved... :( -
Setting parameter in PreparedStatement results in different stored value
Hi,
first of all: this might be an exotic case!
When setting a parameter value of a PreparedStatement using Types.DECIMAL as sql-parameter-type like this:
stm.setObject(x, new Long(92233720368547758l), Types.DECIMAL);the value in the database is 92233720368547758 but 92233720368547760. When I set the sql-parameter-type to Types.BIGINT:
stm.setObject(x, new Long(92233720368547758l), Types.BIGINT);the value is stored correctly. This just happens on values >9223372036854770.
Can anyone explain why? As I changed the jdbc driver a few times I doubt it's a bug in the driver but more a wanted/special behaviour for this sql-type ;)
Regards,
Stefanoh, just found out after decompiling the jdbc driver :D
If the sql-type is Types.DECIMAL and the value is an instance of Number the driver does this here:
new BigDecimal(((Number) VALUE).doubleValue())When calling Long.double() 92233720368547758 results into 9.223372036854776E16 and therefore we already have a different value. I'll just fix our code then to use Types.BIGINT instead of Types.DECIMAL.
Maybe you are looking for
-
Getting a "1140" error while syncing my iPad, everything is current, thanks
Recently I started getting a syncing error (1140) when syncing. Seems to be involved with syncing with iPhoto. I have stop rhe sync with iphoto and the error goes away, but I need to sync with iPhoto, help, thanks
-
POA won't load after Server Crash - 8209 file not found err
Groupwise server crashed recently (apparently from bad RAID controller, which has been replaced). Server is back up an running now (SLES 10 sp3 VM running under XEN, GW 2012 sp1). Have performed a rebuild on Primary Domain and also on single Post Off
-
We have just upgraded our CRM 4.0 sp 6 system to CRM 2007 and have configured the 2007 system according to the best practice guides. When trying to open the default provided interaction center i am getting the following errors in the application are
-
Targeting a specific Spry tab in an A Href
Can i somehow tell the Spry tabs to focus on a tab other than the first one on page load?
-
I have both versions 10 and 12 of shockwave Flash on Firefox OS 26. I wish to delete or remove V10 but can't from any process I know including Windows\system32\macromed\flash path. This deletes both of them . What next?