check if output parameter is null before binding - asp.net

How can i check if an output parameter is null before i bind it to a asp literal, and if it is null i want to just make the literal
hname1.Text = cmd.Parameters("#hotel1").Value
hname1.DataBind()
hname2.Text = cmd.Parameters("#hotel2").Value
hname2.DataBind()
hname3.Text = cmd.Parameters("#hotel3").Value
hname3.DataBind()
hname4.Text = cmd.Parameters("#hotel4").Value
hname4.DataBind()
hname5.Text = cmd.Parameters("#hotel5").Value
hname5.DataBind()

If Not IsDBNull(cmd.Parameters("#hotel1").Value) Then
hname1.Text = cmd.Parameters("#hotel1").Value
hname1.DataBind();
Else
' Manual binding would go here
End If
I believe. Syntax may be a bit hairy as it's been a bit since I've done VB, but the premise should be the same.
This is also assuming cmd.Parameters("#hotel1") will always be a callable object with a Value property. If this could potentially be null, we need to add another comparison to avoid NullObjectReference exception(s).
Also, I hope I understand the question correctly, your mention of "output parameter" without having a Subroutine/Function to look at leads me to believe there's a bit of confusion on semantics.
Version Change
Using IsDBNull to check against empty value

Related

Second dict refering to first dict doesn't register changes to first

dictOne = {'a':1, 'b':2}
dictTwo = {'aa':dictOne['a'], 'bb':dictOne['b']}
print(dictTwo['aa']
# returns 1
If I make a change to dictOne like:
dictOne['a'] = 2
print(dictOne['a'])
# returns 2
but the second dict that refers to the first still returns the original value.
print(dictTwo['aa'])
# returns 1
What is happening here? I'm sure this is somehow an inappropriate usage of dict but I need to resolve this in the immediate. Thanks.
You're extracting the value from the key 'a' inside dictOne with the below piece of code
dictTwo = {'aa':dictOne['a']}
You may find some value in reading the python FAQ on pass by assignment
Without knowing more about the problem, it's difficult to say exactly how you can solve this. If you need to create a mapping between different sets of keys, there's the option to do something like:
dictTwo = {'aa' : 'a', 'bb' : 'b'}
dictOne[dictTwo['aa']]
Although maybe what you're looking for is a multi key dict
The line here:
dictTwo = {'aa':dictOne['a'], 'bb':dictOne['b']}
Is equivalent to:
dictTwo = {'aa':1, 'bb':2}
Since dictOne['a'] and dictOne['b'] both return immutable values (integers), they are passed by copy, and not by reference. See How do I pass a variable by reference?
Had you done dictTwo = dictOne, updating dictOne would also update dictTwo, however they would have the same key values.

KEYWORD_SET in IDL

I am new to IDL and find the KEYWORD_SET difficult to grasp. I understand that it is a go no go switch. I think its the knocking on and off part that I am having difficulty with. I have written a small program to master this as such
Pro get_this_done, keyword1 = keyword1
WW=[3,6,8]
PRINT,'WW'
print,WW
y= WW*3
IF KEYWORD_Set(keyword1) Then BEGIN
print,'y'
print,y
ENDIF
Return
END
WW prints but print, y is restricted by the keyword. How do I knock off the keyword to allow y to print.
Silly little question, but if somebody can indulge me, it would be great.
After compiling the routine, type something like
get_this_done,KEYWORD1=1b
where the b after the one sets the numeric value to a BYTE type integer (also equivalent to TRUE). That should cause the y-variable to be printed to the screen.
The KEYWORD_SET function will return a TRUE for lots of different types of inputs that are basically either defined or not zero. The IF loop executes when the argument is TRUE.
Keywords are simply passed as arguments to the function:
get_this_done, KEYWORD1='whatever'
or also
get_this_done, /KEYWORD1
which will give KEYWORD1 the INT value of 1 inside the function. Inside the function KEYWORD_SET will return 1 (TRUE) when the keyword was passed any kind of value - no matter whether it makes sense or not.
Thus as a side note to the question: It often is advisable to NOT use KEYWORD_SET, but instead resort to a type query:
IF SIZE(variable, /TNAME) EQ 'UNDEFINED' THEN $
variable = 'default value'
It has the advantage that you can actually check for the correct type of the keyword and handle unexpected or even different variable types:
IF SIZE(variable, /TNAME) NE 'LONG' THEN BEGIN
IF SIZE(variable, /TNAME) EQ 'STRING' THEN $
PRINT, "We need a number here... sure that the cast to LONG works?"
variable = LONG(variable)
ENDIF

LLVM converting a Constant to a Value

I am using custom LLVM pass where if I encounter a store to
where the compiler converts the value to a Constant; e.g. there is an explicit store:
X[gidx] = 10;
Then LLVM will generate this error:
aoc: ../../../Instructions.cpp:1056: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.
The inheritance order goes as: Value<-User<-Constant, so this shouldn't be an issue, but it is. Using an a cast on the ConstantInt or ConstantFP has no effect on this error.
So I've tried this bloated solution:
Value *new_value;
if(isa<ConstantInt>(old_value) || isa<ConstantFP>(old_value)){
Instruction *allocInst = builder.CreateAlloca(old_value->getType());
builder.CreateStore(old_value, allocInst);
new_value = builder.CreateLoad(allocResultInst);
}
However this solution creates its own register errors when different type are involved, so I'd like to avoid it.
Does anyone know how to convert a Constant to a Value? It must be a simple issue that I'm not seeing. I'm developing on Ubuntu 12.04, LLVM 3, AMD gpu, OpenCL kernels.
Thanks ahead of time.
EDIT:
The original code that produces the first error listed is simply:
builder.CreateStore(old_value, store_addr);
EDIT2:
This old_value is declared as
Value *old_value = current_instruction->getOperand(0);
So I'm grabbing the value to be stored, in this case "10" from the first code line.
You didn't provide the code that caused this first assertion, but its wording is pretty clear: you are trying to create a store where the value operand and the pointer operand do not agree on their types. It would be useful for the question if you'd provide the code that generated that error.
Your second, so-called "bloated" solution, is the correct way to store old_value into the stack and then load it again. You write:
However this solution creates its own register errors when different type are involved
These "register errors" are the real issue you should be addressing.
In any case, the whole premise of "converting a constant to a value" is flawed - as you have correctly observed, all constants are values. There's no point storing a value into the stack with the sole purpose of loading it again, and indeed the standard LLVM pass "mem2reg" will completely remove such a sequence, replacing all uses of the load with the original value.

How to stop evaluating if the first condion has been passed

I try to evaluate a field in my report but it fails every time :
= IIf(Fields!lectcrs_hrs.IsMissing,
Round(Fields!lectcrs_fee.Value * "1.00", 2),
Round(Fields!lectcrs_fee.Value * Fields!lectcrs_hrs.Value, 2))
in the case of Fields!lectcrs_hrs.IsMissing = true my field is empty and i find that the reason that the second case Round(Fields!lectcrs_fee.Value * Fields!lectcrs_hrs.Value, 2) contains a missing field Fields!lectcrs_hrs .why it checks the second case if it passes the first one !
How to fix this problem ?
The behavior you are looking for is called "short-circuiting" and, unfortunately, the IIf function in Visual Basic does not offer that. The reason being is that IIf() is a ternary function and, as such, all arguments passed into it are evaluated before the function call occurs. A ternary operator (If() in VB 9+), on the other hand, does support conditional evaluation. However, I do not believe that the If() operator can be used as a part of an expression in SSRS.
Given the fact that you are trying to use a field which may or may not exist at run time, I suggest that you create a custom function in your report to handle the proper checking and return values. For reference, take a look at this blog post, which covers the same scenario.

Passing Optional Arguments in Classic ASP for Stored Procedure

I'm trying to run some stored queries in an Access database from an ASP page. I'd like to use an ADO Command object to run the procedure instead of simply sending a string to the database to execute. My trouble is occurring when I try to create the parameters to send to the stored procedure. I'm using the 'CreateParameter' method of the Command object. It takes 5 optional arguments, of which I only want to use two; name and value (arguments 1 and 5 respectively).
I've tried the following approaches to set up the parameters:
1) Using named arguments
command.Parameters.Append command.CreateParameter name:="name", value:="value"
2) Using named arguments inside brackets
command.Parameters.Append command.CreateParameter(name:="name", value:="value")
3) Leaving out optional parameters I don't need
command.Parameters.Append command.CreateParameter("name", , , , "value")
What is a simple way to achieve what I'm trying to do, and why does my syntax fail in these cases? I'm clearly missing something here!
VBScript doesn't support named arguments with or without brackets. All parameters required to pass (specific or blank) for CreateParameter method of the Command object.
For the section 3 in the question, have a look:
CreateParameter(
name`[optional], <- fits ("name")
type [optional, default = adEmpty], <- NOT fits (type is not empty)
direction[Optional default = adParamInput], <- fits (blank)
size [optional default = 0], <- NOT fits (at least 5 for "value")
value[optional] <- fits ("value")
)
So, you should specify at least type and size for a text valued parameter. Direction is adParamInput already.
Const adVarChar = 200 ' From adovbs.inc or Ado TypeLib
command.Parameters.Append command.CreateParameter("name", adVarChar, , 5, "value")
here is an example that can be followed.
http://www.webconcerns.co.uk/asp/accessqueries/accessqueries.asp
see also
http://bytes.com/topic/asp-classic/answers/628368-running-access-stored-queries-parameters
Remember access uses stored queries not stored procedures so some differences apply. For additional information search for
ASP with Access stored queries using parameters - .net

Resources