How To Test A Lamda Expression Variabe Query Result Is Null?.
Mar 13, 2011
var query = from emp in dbEmp.Employees join dept in dbEmp.Departments on emp.DeptID equals dept.DeptID where dept.DepartmentName.Contains(this.TextBox1.Text) select new { EmpID = emp.EmpID, EmpName = emp.EmpName, Age = emp.Age, Address = emp.Address, DeptName
= dept.DepartmentName };
if (query==null) Label1.Text = "no results match your search";
Everything works in the right way, but the label doesn't show the message when query result returns null. The label can show without condition(querry==null). So how to test if a var query result returns nothing?
I have a query that references many tables, however the main record doesnt necessarily have records in the other tables. In my formview itemtemplate, i bind the values of the query but I'm getting an obvious error when the value is null. This is what I'm trying to do: (the field is a boolean btw). These fields are hidden so I don't really care if it gets assigned a temp value or something.
[Code]....
Error: BC30452: Operator '=' is not defined for types 'Object' and 'System.DBNull'.
I have this ListView that has a Drop Down List.Everything works fine (I think/hope) except that the drop down list are not showing its result correctly.This is the code.
Front-End [Code]....
The code behind consist of the page_load and the ItemDataBound [Code]....
I'm having a problem with my Linq to XML query. I'm getting the result data I want, but it's nested so deep that there must be a better way.Here is my XML:
[Code]....
I'm trying to get a list (simple string[]) of all Item IDs where Category Names contains "Other".Here is my Linq:
[Code]....
[Code]....
Here is a snapshot of my result from Visual Studio:The results I want are there ("item100", "item400", "item500"), but buried so deeply in the results var.
I am trying to display this query result in an aspx page.
It is very slow in loading. Here is the query. The inner query inside the outer quesry is the problem.(Please see the underlined part in the query) - (If I remove that part it is very fast.)
select
top 500
--This column is the issue ,Governing_Class=( case when exists (select top 1 tqc.class_code from t_quote_class tqc inner join t_quote_class_premium tqcm on tqc.class_code =tqcm. class_code where tqc.appid=pi.appid and tqc.class_code not in('8742' ,'8810','7380') order by tqcm.premium_amt desc ) then ( select top 1 tqc.class_code from t_quote_class tqc inner join t_quote_class_premium tqcm on tqc.class_code =tqcm. class_code where tqc.appid=pi. appid order by tqcm.premium_amt desc ) ......... From tables
I'm using the ASP Validation control a wanted to test that multiline textbox content was between 2 and 40 characters. Any character can be provided, including the new line character. What would be the expression? What I have below fails.
I have a C# program used to build and deploy a suite of websites.
I would like to programatically interact with IIS so that it changes where the virtual directory for a test system points to based the result of the build.
I have a SQL Data Source that displays records after going through the Query Builder and select "Test Query" yet when I save it, go back to the design mode and select View in Browser I get nothing but a blank screen.
iam using webservice for create customer.by using WSDL(webservice) Url iam able to create customer Successsfully using Createcustomer request class. but in responce iam unable to get Unique ID the reponce object should generate as per SOAP functioanly iam unable to see the result set it is always null. How can i do this i need to capture that Unique ID after creating customer. it's Async mode. In below responce e.result set containning NULL values evn i customercreated in database.how to get my UniqueId in responce. my code:
{ Customer customer = new Customer(); PersonName pn = new PersonName(); pn.FirstName = txtFname.Text; pn.LastName = txtLname.Text; pn.MiddleName = txtMname.Text; pn.Salutation = "Mr."; customer.PersonName = pn; CreateCustomerRequest ccr = new CreateCustomerRequest(); ccr.CreateCustomer = customer; RSWS rsws = new RSWS(); rsws.CreateCustomerCompleted += new CreateCustomerCompletedEventHandler(rsws_CreateCustomerCompleted); rsws.CreateCustomerAsync(ccr); } void rsws_CreateCustomerCompleted(object sender, CreateCustomerCompletedEventArgs e) { CreateCustomerResponse ccresp = e.Result; Page.RegisterStartupScript("inspa", "<script>alert('customer created successfully')</script>"); }
I've created a WCF Service that Performs Insert User, What it does is, it'l get user name, age,gender,address,phone no and inserts these values into SQL database.
Problem is :
These things are working fine, if i give all the values in the WCF Test Client, It's Not working when i din't enter value for Address and click "Invoke" Button, It's throwing an Exception Procedure or Function "Insert_User" Expects
ADDRESS' Which was not supplied. I've created the SQL table Which allow Null Values for Address.
I've did the same Operaion in WebService also, there it's working fine, if i din't enter any value for tha Allow Null Colums, it's accepting the Null value and inserting into Database.
Why this Problem comes in WCF Test client, Guide me to Get rid of this Problem.
I am using httpcontext.Current in one my action method and i created the ms test method for testing this action and also i created the Mock object for httpcontect,but when i am trying to run the MS test script i am getting null reference exception from the line which i am using httpcontext.current in the action method.
I have an ASP.NET web service which returns an XMLDocument. The web service is called from a Firefox extension using XMLHttpRequest.
var serviceRequest = new XMLHttpRequest(); serviecRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
I consume the result using responseXML. So far so good. But when I iterate through the XML I retrieve nodeValue - nodeValue is always null. When I check the nodeType the nodeType is type 1 (Node.ELEMENT_NODE == 1).
Node.NodeValue states all nodes of type Element will return null.
In my webservice I have created a string with the XML i.e. xml="Hank"
I then create the XmlDocument XmlDocument doc = new XmlDocument(); doc.LoadXML(string);
I know I can specify the nodetype using using CreateNode. But when I am just building the xml by appending string values is there a way to change the nodeType to Text so Node.nodeValue will be "content of the text node".
MGEntities db = new MGEntities(); [HttpPost] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); if (createStatus == MembershipCreateStatus.Success) { FormsService.SignIn(model.UserName, false /* createPersistentCookie */); MembershipUser myObject = Membership.GetUser(); Guid UserID = (Guid)myObject.ProviderUserKey; MyProfile profile = new MyProfile(); profile.Address = model.Address; profile.City = model.City; profile.Zip = model.Zip; profile.State = model.State; profile.UserId = UserID; Debug.Write(profile.State); db.aspnet_Profiles.Add(profile); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } }
This is my MyProfile Class:
namespace MatchGaming.Models { [Bind(Exclude = "ProfileId")] public class MyProfile { [Key] [ScaffoldColumn(false)] public int ProfileId { get; set; } public Guid UserId { get; set; } [DisplayName("Address")] public string Address { get; set; } [DisplayName("City")] public string City { get; set; } [DisplayName("Zip")] public string Zip { get; set; } [DisplayName("State")] public string State { get; set; } } }
After the linq query is executed, i check my database and nothing is added. I am using POCO for my entities. Here is my class:
namespace MatchGaming.Models { public class MGEntities : DbContext { public DbSet<MyProfile> aspnet_Profiles { get; set; } } }
I use the follwoing code to get a value from the SQL query. But now i would like to use some sql function like Sum() count() ... and i would like to get the result of that. vb Code: Dim constg As New SqlConnection constg.ConnectionString = "Data Source=m......." constg.Open() Dim payrollquery As String '= ("SELECT * FROM xxxxx.nnnnn WHERE ID IN(" & ID & " ) AND sent = 'U' ") Dim cmd3 As New SqlCommand(sqlstr, constg) Dim reader As SqlDataReader = cmd3.ExecuteReader
i need to make 2 funtions on an ASP.NET c# page working with an SQL server (using Visual Web Developer 2010 Express) the 1st one is a simple serach and i've done the 2nd thing is an update , the sp is like:(it works in SQL)
UPDATE [lens] SET [qty] = @b+@c WHERE [id] = @a
@a is the id which user input in the textbox1
@b is an number user input in the textbox2
now @c should be the result of an query "select [qty] from [lens] where [id] = @a"
so ,the new value of [qty] will be the "old valus"+"valus in textbox2"