How To Check Null EventArgs

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


Similar Messages:

Lambda Check For Null?

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

ADO.NET :: How To Check If ExecuteScalar() Is Null

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

C# - Check A Datareader For Null?

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

Check For Null With HtmlAgilityPack?

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

ADO.NET :: Check For Null Values From DataReader

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

C# - Check If Datareader Is Null Or Has No Rows?

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

Web Forms :: Check Whether Session Is Null?

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

Check If Output Parameter Is Null Before Binding?

Jan 26, 2011

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

[code]...

View 1 Replies

Web Forms :: How To Check Whether The Int Parameter Is Empty Or Null

Aug 17, 2010

I have set the value of an int parameter to the attribute of a textbox.The textbox can be empty or null, how to check whether the parameter is empty or null?

View 5 Replies

Access :: C# - How To Check Image Field Is Null Or Not

Mar 28, 2011

Actually i have a table with 7 columns

1) Title varchar(100)

2)Description varchar(300)

3)ProfilePicture varbinary(max)

4) Image1 varbinary (max)

5)Image2 varbinary(max)

6)Image3 varbinary(max)

7)Image4 varbinary(max)

Image1,2,3,4 are not a mandatory fields so, when i inserted, i check it if it is not there then i insert null value, Now problem is when i retrive them if there is a row contain image1,2 are image content and 3,4 are null values dataset also filling as it is in database but when i checking like

[code]....

it shows error like

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.

View 3 Replies

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

ADO.NET :: Check If Statement Is Null In Linq Sql, Then Continue?

Mar 12, 2011

Right now I have an error if f.ParentID is null:

DataSet1.TreeItemRow[]
TreeItemRows = (from f
in tidt
where (f.ParentID == TreeItemId)
select f).ToArray();

I must continue if f.ParentID is null, I don't want to include null fileds in the array. What is the right syntax for that is linq sql?

View 17 Replies

Web Forms :: Check If QueryString Parameter Has Value Or It Is NULL In C#

Jun 25, 2012

How to check the query string value null, if null then display the default value instead of object reference error.

View 1 Replies

Check For A Null Object Reference When Validating Forms In MVC?

May 28, 2010

I'm experimenting with validating forms in the asp.net MVC framework. I'm focusing on server side validation for the time being. I've come across an error that I'm not sure how to rectify. System.NullReferenceException: Object reference not set to an instance of an object. The code that throws the error is:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="ID")] MembersCreate mc )
{
mc.Modules = ModuleListDataContext.GetModuleList();
ViewData.Model = mc;
//Validation using ModelState
//
//
//line below errors when form field is empty
//
if ((string)mc.Member.Username.Trim() == "")
ModelState.AddModelError("Member.Username", "Username is required.");
if (!ModelState.IsValid)
return View();
try
{
// TODO: Add insert logic here
return RedirectToAction("Index","Home");
}
catch
{
return View();
}
}

When I put spaces in the field it performs exactly as i want, but if I leave the field blank and press submit I get the error. What's the best way to avoid this error and still validate blank form fields?

View 1 Replies

DataSource Controls :: How To Check For Both Empty And Null Fields

Jan 28, 2010

How do I check if my value is empty AND Isnull? I need to check for both, using ISNULL is not enough because the data can change just so that it is empty.

how I can change my query to accommodate this?

[Code]....

View 5 Replies

DataSource Controls :: How To Check That Data Reader Is Null

Jun 4, 2010

[Code]....

but if table is empty i.e. there is no record for Store_no=storeno then it bill_id = (Convert.ToInt32(reader[0]) + 1); give a Null exception.

I want to set bill_id=1 if there is no previous record in table of that particular store number. then How to do this.

i.e. How to check that reader[0] is null

cmd1 = new SqlCommand(" Select Max(Bill_No) From Bill_Record Where Store_no='" + storeno + "'", hookUp);

View 3 Replies

C# - Check The Null Of An Embedded Linq To Entities Statement?

Dec 15, 2010

Using linq to entities i am connecting to a database, the database has tables in it that has payments that have a multi to multi relationship with jobs. This is acheived via an allocs table. I want a list box with all the jobs that has a column called due price which takes all of the allocations of payments for this job and takes that away from the job price. However, using the below linq to entities statement. The problem is that if the job has no allocations it returns null and therefore the due payment is empty. What i really want is for the due payment to be the job price if there are no allocations however, i cannot think of a way around this.

var jobs = from j in data.jobs
where j.property.customer.id == customerid
&& j.completed != null
select new
{
j.id,
j.price,
dueprice = j.price - ( from a in data.allocs
where a.job.id == j.id
select a.amount ).Sum(),
lineone = j.property.lineone,
postcode = j.property.postcode,
jobtype = j.jobtype.name,
j.completed
};

View 3 Replies

C# - Reading XML Using XDocument & Linq - Check If Element Is NULL?

Apr 7, 2010

I'm using LINQ together with XDocument to read a XML File. This is the code:XDocument xml = XDocument.Load(filename);

var q = from b in xml.Descendants("product")
select new
{

[code]...

View 3 Replies

Asp.net - Use Of Eventargs In DoPostback Function?

Feb 10, 2010

This may be a basic question. I know __doPostback() function accepts 2 arguments, eventtarget and eventargs. eventtarget is used to identify the control that causes postback. Then what is the use of eventargs in doPostback function?? I saw the _doPostback function always set the __EVENTARGUMENT hidden field to nothing for any postbacks caused thro controls with even autopostback to true or a control like linkButton.

View 2 Replies

Active Directory/LDAP :: Check If Length Is Null Or Empty?

Nov 17, 2010

I'm fetching som data from AD and I notice that I'm getting an exeption and notice that one of the users field that I'm fetching is empty, how can I prevent exeption.

Here is the code:

[Code]....

View 4 Replies

WebMatrix :: Check For Null / Empty Strings On Dynamic Objects?

Aug 20, 2010

What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

View 5 Replies

Check Whether DateTime Data Type Variable Is Null / Empty?

Oct 6, 2010

How i do check whether DateTime data type variable is null/empty in asp.net ?

View 5 Replies

Data Controls :: Query For Both Empty Or Null Values Check Together

Mar 14, 2012

this is my sql query and its work fine in my code but it only check ParentDeptID IS NULL  it not working when ParentDeptID   field is empty how can i check it

("select DeptID,DeptName,(select count(*) FROM HrDept " _          
& "WHERE ParentDeptID=sc.DeptID) childnodecount FROM HrDept sc where ParentDeptID IS NULL ", _          
objConn) 

View 1 Replies

Web Forms :: Modifying A Line For EventArgs E

Jun 12, 2010

what I can replace the bold line with to get it working with EventArgs e? I copied this code from a button function with CommandEventArgs e.

protected void btnNextStep_Click(object sender, EventArgs e)
{
if (cboxShippingSelect.Checked == true)

[Code]....

View 8 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved