SQL Server :: In Sql Function Check To See If Variable Is Null?
Feb 4, 2011
Inside a function I need to check to see if a variable value is null, how to do this? I implemented the code but its not returning the value I thought it would return.If it's null I want to set the value of the variable, else I want to query the value from a table
[Code]....
View 5 Replies
Similar Messages:
Oct 6, 2010
How i do check whether DateTime data type variable is null/empty in asp.net ?
View 5 Replies
Sep 26, 2010
I want to send an image to a stored procedure variable that is varbinary(max) field, It works correctly when an image selected by fileupload and my image property has image file, and it can send to stored procedure. but when fileupload is empty I want to send NULL to stored procedure variable that is varbinary(max). I use DbNull.Value in C# code. But error occurs. What should I do for send Null to stored procedure?
View 3 Replies
Mar 18, 2010
I have a problem with a SessionVariable. I will explain what is happening:
1. From the default.aspx I send Session["LoginByAdmin"] = "Dummy"; and then redirect to this page where I have the code below. So the Page_Load sees that this Session["LoginByAdmin"] != null and enter this page. This works fine !
2. In the Page_Load, I later fill a ListBox1 with foldernames.
3. With Button1_Click1, I will now delete the choosen Folder in the ListBox1 wich works fine the first time and the ListBox updates the new existing folders in the ListBox. (I have wrapped this inside an updatepanel)
The problems comes now when I try to delete a choosen folder in the ListBox1 the second time in a row. When I select a Folder in the ListBox1 and now Press Button1, I will be redirected to "Default.aspx". This meens that this code is running: (That meens that Session["LoginByAdmin"] == null and I have not set this to null anywhere. This is my big question how this variable can be = null here?
if (Session["LoginByAdmin"] == null)
Response.Redirect("Default.aspx");
break;
[Code]....
View 5 Replies
Mar 16, 2010
why I get the null value for activationLink variable in the following code:
public ActionResult Activate(string activationLink)
{
if(string.IsNullOrEmpty(activationLinkROWGUID)) return View("ActivateClientError");
if (linkROWGUID != Guid.Empty)
{
return new CServerFacadeFactory().GetServerFacade.ActivateOperator(activationLinkROWGUID) ? View("ActivateClient") : View("ActivateClientError");
}
return View("ActivateClientError");
}
the link which I use is as follows : http://localhost/ActivateClient/Activate/xxxActivationLink
View 1 Replies
May 25, 2010
Can i initialize var with null or some empty variable.
View 7 Replies
Mar 30, 2011
how to check var variable is empty
View 3 Replies
Mar 29, 2011
var pq = attributes.SingleOrDefault(a => a.AttributeName == PasswordQuestion").AttributeValue;
The above code will throw an error if null. What is the best way to handle this?The below code would work, but I can't help but feel there's a more graceful way?
var pq = (attributes.SingleOrDefault(a => a.AttributeName == "PasswordQuestion") != null) ? attributes.SingleOrDefault(a => a.AttributeName == "PasswordQuestion").AttributeValue : null;
View 1 Replies
Oct 21, 2010
I know for a fact that the SQL statement below returns NULL but my code statement "if (obj != null)" is not working.When I debug it I see a value of {} ... not sure what that is. Here is my code:
[Code]....
So, even if SQL returns NULL, it still validates obj as NOT NULL !
View 3 Replies
Feb 11, 2010
I have Sub that requires EventArgs as below.
Sub Testing(ByVal sender As Object, ByVal e As EventArgs)
If I want to call the Sub from PageLoad event, I wrote like this Testing(nothing,nothing)
Then, in the Sub, I would like to check If Argment is Nothing or not
Dim testID As String
If (CType(sender, LinkButton).CommandArgument) = Nothing
testID=Request.QuerySting("myID")
ELSE
testID=(CType(sender, LinkButton).CommandArgument).ToString
End If
I get Null error at if statement (If (CType(sender, LinkButton).CommandArgument) = Nothing)
View 1 Replies
Feb 10, 2011
I have an aspx page which allows a user to submit modified entries into the database, but when the user clicks Submit to fire the stored procedure I want to first run a check to see if a modified row with the same relationship exists.I am passing the results of the following query:
SELECT SwitchRoom.ModifiedID FROM SwitchRoom WHERE
SwitchRoomID = @ChkSwitchRmID", constring;
into a DataReader to determine if that relationship exists.I need it to determine whether the reader returns NULL to allow the procedure to execute, if it doesn't, then don't allow the user to save the information.I've tried the following:
if (dbreader = NULL)
{
Fire Procedure
}
else
{
"Error Message"
}
and I've even tried passing the reader into a datatable and running it against that without any luck.
View 5 Replies
Apr 4, 2011
How do you check for null with HtmlAgilityPack? I'm getting "Property or indexer 'HtmlAgilityPack.HtmlNode.HasChildNodes' cannot be assigned to -- it is read only" with the following.
if (Node.Element("TD").HasChildNodes = DBNull.Value)
I"m getting "Object reference not set to an instance of an object. " with
if (Node.Element("TD").HasChildNodes)
View 1 Replies
Feb 3, 2011
my asp.net app uses dynamic stylesheets. so each of my pages uses a pre_init method to load the relevant stylesheet. the stylesheet is the same for ALL users of the app.for each page load, i don't want to query the database to determine which stylesheet to use. therefore, I simply load the stylesheet from a STATIC variable that I store when the app starts.
works fine locally. however, on the production server the STATIC variable is reset to Null after about 5 minutes. why is that?? is there a better way for me to handle this? Should I change something in IIS? Should I change the methodolgoy I am using to retreive the stylesheet?
Each .aspx page includes:
[Code]....
BusinessLogic.Admin:
[Code]....
BusinessLogic.Admin parameter
[Code]....
View 4 Replies
Sep 10, 2010
xamount is receiving this message on the last line. The session is being set in the previous page. Is there a way to resolve the message or should I just use a previous page postback
[Code]....
View 9 Replies
Dec 23, 2015
If you click a button that takes you to a page using <a href....> is the session variable lost?
In VS testing the web app everything works perfect, but when it is pushed to production when the page is loaded the Session Variable is null?
View 1 Replies
Jul 14, 2010
I'm evaluating two options of accessing a server side data on client side. Little bit confused about the efficiency or may be you can call it as finding best approach to do it.
I need to access a server side data may be an integer value in javascript on client side. I know about two options to do it.Create a public variable or property on server side and set it to javascript variable on client side as below:
var value = eval(<% =value %>);
Create a asp hidden variable and set value in this hidden variable from server side and access it through javascript using document.getElementById().
Which is the best approach and what are the pros and cons?
View 1 Replies
May 14, 2010
I have designed a asp.net page which create graphs. I have written a class file (which contain a function to render the graph,a function for entering data named insertdata(string[] s,double[] d)) in App_code folder. I pass the value into the insertdata during page load_event. I saw a feature of googlechart.when you pass the value in url address bar it will create a graph according to that passed value. how can i pass the value into the insertdata() function through url address?
View 2 Replies
Feb 16, 2011
I have the following code
public class ProductDetails
{
private string _productid;
public string ProductID
{
get { return _productid; }
}
private string _description;
public string Description
{
get { return _description; }
}
private string _image;
public string Image
{
get { return _image; }
}
public ProductDetails(string productid, string description, string image)
{
_productid = productid;
_description = description;
_image = image;
}
}
public class DataAccess
{
private static string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
public ProductDetails GetProductDetails()
{
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("ProductDetails", con);
cmd.CommandType = CommandType.StoredProcedure;
string productid = HttpContext.Current.Request.QueryString["productid"];
cmd.Parameters.Add(new SqlParameter("productid", SqlDbType.NVarChar)).Value = productid;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
ProductDetails pro = new ProductDetails(
(string)reader["ProductID"], (string)reader["Description"], (string)reader["Image"]);
reader.Close();
return pro;
}
}
protected void PopulateControls()
private DataAccess da = new DataAccess();
{
ProductDetails product = da.GetProductDetails();
if (product.Description == String.Empty)
{
lblDescription.Visible = false;
}
else
{
lblDescription.Text = product.Description;
}
}
In the last piece i want to check if the Description field is null or empty in order to hide the label control but i get an error if i write: if (product.Description == DBNull.Value) and can only use ring.Empty. But i want to check for NULL values as well..
View 3 Replies
Apr 4, 2011
So I took over this project and one page is throwing a lot of errors. I would need to refactor the whole thing but as always time is an issue.
In one case the code check's whether a datareader has any rows and if not go to an error page. However as the code is now the datareader can be null (didn't successfully connect to db) and in those cases I can't use
if (!dr.HasRows)
//
becasuse it obviously gives me 'nullreferenceexception was unhandled by code'. I tried with !dr.Read but same thing.
A part of the code is something like
SqlDataReader dr = null;
try
{
//connect to db etc
dr = DbHelper.GetReader("sp_GetCustomer", param);
}
catch
{
//show an error message
}
// and then:
if (!dr.HasRows)
{
}
View 2 Replies
Aug 27, 2013
If i have a page in which I want to check whether session is null.
If it is null it will redirect to other page.
But i also have a  if (!Page.IsPostBack)
so i will check the session inside this  if (!Page.IsPostBack) or outside it?
View 1 Replies
Mar 29, 2011
I would like to enquire about a seemingly basic problem that i am struggeling with. I have been trying to add information to an access database and as i am inserting this information I get the error message stating that I tried to assign the Null value to a variable that is not a Variant type. I was thinking that it could have something to do with the primary key being set to automatic number but this also does not seem the problem.
View 2 Replies
Jun 18, 2010
I have this
var result = general.GetInformation(int.Parse(ID), F_account, F_Info, Types);
this GetInformation is my Entity.Getinformation class.. when I am trying to assign result globly I am getting Cannot Assign to implicit typed local variable?
var result = ?
what should I assign in global?
View 3 Replies
Jun 5, 2010
I've got a Site.Master file I've created to be my template for the majority of the site, with a navigation. This navigation is dynamically created, based on a recursive Entity (called Page) - Pages with a parentID of 0 are top level, and naturally each child carries it's parent's Id in that field.
I've created a quick little HTML Helper that accepts the ID of an Page and generates the nav by doing a foreach on the children that have a parentId matching the passed Id. On the majority of the site, I want the Site.Master to use a parentId of 0, but if I'm on a strongly typed View displaying a Page, I naturally want to use the Id of the page.
Is there a way to do such conditional logic in a Site.Master (and, does that violate MVC rules)? "If I'm on a strongly typed Page of /Page/{Id}, use the Id render nav, else use 0"
View 2 Replies
Oct 19, 2010
Ok, I keep running into this problem
In my aspx I am calling a simple function.
But the problem is, that the function is either, string, integer, etc.
If there's null's in the data, the function explodes because it's set to a string or integer, etc.
How can I make the function accept both a null, and another data type so that I can
write some if then's to do different things if it is null or another data type.
Here is the code to give you an idea
[code]....
View 9 Replies
Oct 2, 2010
I have 2 table Table A, Table B.
Table A - Parent Table
ID - Uniqueidentifier not null(PK)
Table B -Child Table
ID - uniqueidentifier null(FK, TableA)
I have a stored procedure to insert data into Table B, but when I tried to insert a null value into column ID of table B, this error came up:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tableB_tableA". The conflict occurred in database "database name", table "table A", column 'ID'.
The statement has been terminated.
The insert statement in asp.net is like so:
sqlcommand.parameter.add(New Sqlparameter("ID", Nothing))
I am guessing adding nothing to the null value column is the problem, but i don't know how to fix it... The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tableB_tableA". The conflict occurred in database "database name", table "table A", column 'ID'.
View 5 Replies