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)
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?
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 !
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.
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
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..
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) { }
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?
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[]'.
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
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?
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.
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 };
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.
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.
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?
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)