.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Subquery returning more than 1 value

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :ASP.Net
Hey Forummers,I have a problem regarding this code:select NotificationID, (select u.UserName from aspnet_Users u, notifications n where u.UserId = n.FromID) as 'UserName', [Message], DateCreated, TypeID from Notifications n, aspnet_Users u where ToID = '92FBC025-5E08-4533-AF36-BF208391E4D6' and Accepted = 0SELECT NotificationID, (select u.UserName from aspnet_Users u, notifications n where u.UserId = n.FromID) AS 'UserName', [Message], DateCreated, TypeIDFROM Notifications n, aspnet_Users uWHERE ToID = '92FBC025-5E08-4533-AF36-BF208391E4D6' AND Accepted = 0The problem lies in the code in bold. and the error message is as follows:Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.I have a table called Notifications which has ToID which is a uniqueidentifier of the receiver and FromID which is a uniqueidentifier of the sender.What I want to achieve is to return a set of notifications to the client side according to the ToID of the table, but I do not want to display the FromId GUID in the client where the ToID is linked to. Instead I want to display a username in place of the FromID GUID which field is located in the aspnet_Users table.Any help would be appreciated and thanks in advance... =)CheersZeph

View Complete Post

More Related Resource Links

Returning a DataSet From a Web Services: Step-by-Step

This Example Shows how to create a webservice which returns a DataSet and a Client Which displays the DataSet in a Grid.


This Example Shows how to create a webservice which returns a DataSet and a Client Which displays the DataSet in a Grid.

Linq Subquery



I have a query that looks like this in SQL:

FROM StockMateriaPrima SMP
WHERE SMP.Fecha = (SELECT Max(Fecha)
                    FROM StockMateriaPrima SMP2
                    WHERE SMP2.Id = SMP.Id )

Can anyone tell me how to write this query using LINQ in VB.Net ?

Thanks !

Returning datas from two excel file



I used the below code to return the datas from one excel file. My question is if i suppose need to get the records from morethan one excel file using joins, how it is possible.

   string connString = ConfigurationManager.ConnectionStrings["xls"].ConnectionString;
        // Create the connection object 
        OleDbConnection oledbConn = new OleDbConnection(connString);
         // Open connection
            // Create OleDbCommand object and select data from worksheet Sheet1
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
            // Create new OleDbDataAdapter 
            OleDbDataAdapter oleda = new OleDbDataAdapter();
            oleda.SelectCommand = cmd;
            // Create a DataSet which will hold the data extracted from the worksheet.
            DataSet ds = new DataSet();
            // Fill the DataSet from the data extracted from the worksheet.
            oleda.Fill(ds, "Employees");




Entity Data Model and database view returning the same columns as there are in a table


When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined. 

How do I do something similar for a view?

I mean assuming I have a view like this

CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...

(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.

var foos = myDB.FilteredFoos.Include("Bar").ToList();

foreach (Foo foo in foos) { ...

Thanks, Jenda

SPDataSource returning 0 results when used in CrossList Mode



I'm writing a web part in C# to query several document libraries, using a SPDataSource with the results going to a SPGridView.

I got the query to work just fine with a single document library, but when I switched the SPDataSource to CrossList mode (and added the "Web" and "Lists" tags to the query), I end up with no results. I've done a lot of digging around on the web for examples of how to do this correctly, but always end up with the same result, no hits.

These are the only properties I'm setting on the data source:


ds.DataSourceMode = SPDataSourceMode.CrossList;

ds.UseInternalName = true;

ds.SelectCommand = queryString;

The query string looks like this (I added the formatting for readability... the actual query string is all a single line):

<Webs Scope='SiteCollection'></Webs

Control Values When Returning to Page


Why do controls value not persist when returning to a page (e.g. via browser back button)?  If I set control values without utilizing a post back the controls will maintain their last value when I return to the page.  If I set a control value and then call a post back, the control value is reset to the default value when returning.

I have many pages with a gridview, and a textbox which is used to filter the gridview contents.  I set the filter textbox, filter the gridview (postback), go to another page, and when I return to the gridview page (via back button), my filter textbox is reset empty, and the gridview is the original (unfiltered) data.

What concept am I missing here?

Thanks in advance...

Action method returning an ActionResult used in a Action method


Hell all,

I have the Index action method calling a method that itself is an action method.

Example :

public ActionResult Index()
   //do stuff
   ActionResult result = MethodB();
   // ?? what to return here ??

public ActionResult MethodB()
   //do stuff

  return View("Index);

What to do in this case ?

VS2010 designer problems with custom markup extensions returning FontFamily

App.xaml: <Application x:Class="CustomMarkup.App"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:int="clr-namespace:CustomMarkup"              xmlns:ext="clr-namespace:ExternalMarkupExt;assembly=ExternalMarkupExt"              StartupUri="MainWindow.xaml">     <Application.Resources>         <Style x:Key="MyStyle">             <Setter                  Property="Control.FontFamily"                  Value="{ext:ExtMarkupExt {x:Static int:Resources.FONTFAMILY_NAME}}"/>         </Style>     </Application.Resources> </Application> MainWindow: <Window x:Class="CustomMarkup.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x=&quo

Subquery returned more than 1 value.

Hello, I need a gander at this query to figure out what i'm doing wrong. update Performance set pmpg = (select PMPG from Performance_Calculator where EFFDT_Converted = (select CAST(FLOOR(CAST(getdate() AS FLOAT)) AS DATETIME)) and Performance.DR_CODE = Performance_Calculator.FW_OWN group by Performance_Calculator.FW_OWN, Performance_Calculator.PMPG); basically the performance calculator, in the subquery, does return around 320 rows of data.  I thought the where clause would match up the rows of data and insert the pmpg into the performance table but instead I get subquery returned more than  1 value.  This is true but only if the performance_calculator.fw_own = performance.dr_code wasn't there.  I'm confused on this... any suggestions?

EnumAvailableSqlServers() not returning version information

I am unable to consistently get full information from the smo call EnumAvailableSqlServers. If SQL Browser is running, it returns version info only for the local machine, never a remote machine. I've tested this from several different servers. It IS NOT a firewall issue, there is not firewall or any other restrictive apparatus/software between the servers. #load SMO assembly $v = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') # need version to load version specific SMO , makes code universal # credit to Allen White .. sqlblog.com $p = $v.FullName.Split(',') $p1 = $p[1].Split('=') $p2 = $p1[1].Split('.') if ($p2[0] -ne '9') { [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended') | out-null [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SQLWMIManagement') | out-null } ################ [Data.DataTable]$instances = [Microsoft.SqlServer.Management.Smo.SmoApplication]::EnumAvailableSqlServers() $instances

WebFaultException throwing a "not handled by user code" error and returning an HTTP 500 to the clien

I am trying to return a BadRequest and simple message when implentation throws an error in a WCF REST service, but the WebFaultExcption itself is throwing an exception and returning an HTTP 500 instead. Any ideas on why this might be happening? Here is a short code snippet: [WebDispatchFormatter] [WebHelp(Comment="Initiate an immediate or callback appoinment request")] [WebInvoke(UriTemplate = "InitiateContact", Method = Verbs.Post)] public string InitiateContact(AppointmentRqst rqst) {      string ret = string.Empty;      rqst.DeviceId = Helper.GetHttpAuthHdrDeviceId();      try      {          ret = impl.InitiateContact(rqst);      }      catch (Exception ex)      {          throw new WebFaultException<string>(ex.Message, HttpStatusCode.BadRequest);      }      return ret; }

Returning custom error messages with an UserNamePasswordValidator

Ok, my head hurts from banging it against the wall. I'm new to WCF, I have searched for a solution for days, please help a desperate fellow programmer if you can :-( I have a WCF service hosted in IIS, I implemented a UserNamePasswordValidator, and it seems impossible to find a way to return a custom error message to the client when the user is not allowed in, this blows my mind. I have searched everywhere, many are asking the same question since 2006 and so far I haven't found an answer that works. If you are thinking of replying that it is not secure to return a custom error message to an unauthenticated client, please save yourself some time and don't do it. There are multiple enterprise business scenarios that this is required. Just in our organization an account could be locked out, in which case the user must be directed to the IT department to get it unlocked, it could be that the credentials are correct but the user hasn't paid their fees in which case they must be directed to the appropriate department, or it could even be that the user tried to access the service during a time of the day in which the service is not available. From searching around, I have tried doing the things below in the Validate method, however the client always receives a MessageSecurityException, which contains none of the custom messages that were originally thrown, neither in the object,

Sum With SubQuery

Hi people i am looking for This solution SELECT   funcionarioId, (SELECT SUM(Carga.ValorTotal) FROM CARGA WHERE Carga.ViagemId = Viagem.ViagemId) FROM Viagem i have this Query and it is Working Well and the result is: FuncionarioId | Value 1                   3010.00 2                   6000.00 1                   NULL 2                   50000.00 3                   2556.00 2                   300.00 4                   NULL  What i want is to SUM this SUM(VALUE) for each FuncionarioId, i dont have that column, those values is calculated from (SELECT SUM(Carga.ValorTotal) FROM CARGA WHERE Carga.ViagemId = Viagem.ViagemId) FROM Viagem. Thanks

Subquery returned more than 1 value

SELECT (SELECT fare_amount FROM fare_tab WHERE (class_code = 'ECO')) AS Economy, (SELECT fare_amount FROM fare_tab AS f2 WHERE (class_code = 'TOU')) AS Tourist FROM fare_tab AS f1 I always received an error of: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. How can I solve this?

Error calling WCF service that is returning list.".Debugging resource strings are unavailable ......

Ok.this is just making me frustrated... Here is step by step of what I am trying to do (& not able to) 1. I am calling WCF service hosted in a SharePoint 2010 site from a silverlight app in same domain (So no cross doman I guess). 2. I use Linq to Sharepoint for querying the DB. 3. I am having a list "machines" in Sharepoint 2010 that is having a lookup column from Other list called "part" 4. My WCF method GetAllMachines() works perfectly well when it skips the lookup column "partname" & returns List of type machineitem. 5. But problem occurs when I add machineitemobject.parts.partsname in my Linq to Sharepoint query . My service gives the error not found Async_ExceptionOccurred] Arguments: Debugging resource strings are unavailable." 6. Note that return type of my Method is List<machinesitem> 7. The point to note here is that I use SPMETAL tool to generate the LINQ class that maps the lists . So When I try to query the lookup column it tries to add List item of the type class & that is what causing the error. Is it because I am not using datacontract in my service (but it returns the strings & all private members of machines list e.g. name,title etc) Is it making the attribute Serialisable will solve the error ??? I am kind of lost in it ...Plss help!!   Thanks

Procedure for returning Lift chart score

I am using decision tree with a mix of continous and discrete variables to predict a continous variable. Is there a procedure/function available to: 1. retrieve the score value generated by the lift chart>scatter plot 2. to mimic the GUI functionality under Mining Acccuracy Chart>Input Selection>Specify a different data set. For example the procedure would take in the Model Name, DataSet/View with the testing data and return the Lift Chart score for the testing data specified In summary, I am trying to call the 2 steps above programmatically instead of using the GUI.. i.e., of selecting a different dataset for a particular model to retrieve the lift chart score. Using the scores, I intend to monitor the accuracy of the model continously over a period of time in the future to see if the data structure/rules have changed and model needs a retrain/rebuild. Thanks    

How to write query with subquery more efficient

Hello, I have this query which generates sick days. I have a sick start date and end date, and by joining it with a date table I get all sick days for each employee. But as you can see i select a number of fields, but in the subquery i select a number of fields which are the same. Is it possible to write it more efficient? Thans in advance! SELECT z .ziekmeldingID, z .hrmID, z .ZiekStartDatum, z .ZiekEindDatum, z .ZiekStartTijd, z .ZiekEindTijd, z .ZiekOpen, z .ZiekTypeID, z .ZiekRedenID, z .ZiekStart_KEY, z .ZiekEind_KEY, z .Verzuimduur, D .Datum AS ZiekDag,   CAST(CONVERT(char(8), D.Datum, 112) AS int) AS ZiekDag_KEY, z .hr301_date, z .PercentageZiek, z .PercentageHersteld FROM     (   SELECT dbo .hr300.hr300_obj AS ziekmeldingID, dbo .hr300.hr300_date_start AS ZiekStartDatum,   CASE   WHEN dbo.hr300.hr300_date_end IS NOT NULL   THEN dbo.hr300.hr300_date_end   ELSE getdate()   END AS ZiekEindDatum, dbo .hr300.hr300_time_start AS ZiekStartTijd, dbo .hr300.hr300_time_end AS ZiekEindTijd, dbo .hr300.hr300_open AS ZiekOpen, dbo .hr300.hr104_obj AS ZiekTypeID, dbo .hr300.hr038_obj AS ZiekRedenID, dbo .hr300.hr200_obj AS hrmID,   CAST(CONVERT(char(8), dbo.hr300.hr300_date_start, 112) AS int) AS ZiekStart_KEY,   CAST(CONVERT(char(8), dbo.hr300.hr300_da
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend