C# - The Query Results Enumerated More Than Once?

Mar 17, 2011

datacontextclass dc=new datacontextclass ();
var news= dc.GetNewsCompany(Int64.Parse ( _idCompany));
if (news.GetEnumerator().MoveNext())
foreach (var item in news)

return error:{"The query results cannot be enumerated more than once."}

how can check result != null in LINQ;

View 3 Replies


MVC :: How To Get ModelMetadata For An Enumerated Type

Nov 14, 2009

I am having trouble getting the ModelMetadata for elements accessed through an IEnumerable type. Here is enough code to explain what I mean:


As you can probably tell, what I am trying to figure out is how to get the "d" format specified with the data annotation to be the format for the column in the grid. What seems to be tripping me up is the fact that the Transactions property of the model is defined as IEnumerable<Transaction>.

I can get this far but no farther:

var transactionsMetadata = ViewData.ModelMetadata .Properties.Where(p=>p.PropertyName=="Transactions").First();

Once I get to this point, the transactionsMetadata.Properties returns no members.

View 3 Replies View Related

How To Add A Record To Query Results

Sep 22, 2009

I have a query that gives me a location, startDate, endDate. I need to add to the location a record that would say "Show more" if there is more then 4 records returned from the query.

I have tried a bunch of different things but i am not sure if i am doing this right.


from this result I need to add the "Show More" at the end of the 3 results returned...

I found a sample but not sure if this is what i need to do

var results = query.ToList().Concat(new[] { new { Location = "Show More"}});

if so it screams at the query part and I am not exactly sure where I would need to add this to add it to the bottom of the 3 returned...

View 1 Replies View Related

Display Wmi Query Results In Web Page

Apr 28, 2009

I am trying to figure out how to be able to query a remote server using wmi and then display the results in an aspx web page using vb.net. I have downloaded and am using the WMI Code Creator to browse and determine which WMI queries I want to use, but all of the vb.net code it generates uses the console as the output. I am still new to this level of vb.net web development and do not know how I can modify this code to display the wmi query results on a web page. Here is a sample bit of WMI code that the tool generates to get the operating system, make and model of the remote system.


Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class MyWMIQuery
Public Overloads Shared Function Main() As Integer
Dim searcher As New ManagementObjectSearcher( _
"rootCIMV2", _
"SELECT * FROM Win32_ComputerSystem")
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("Win32_ComputerSystem instance")
Console.WriteLine("Manufacturer: {0}", queryObj("Manufacturer"))
Console.WriteLine("Model: {0}", queryObj("Model"))
Console.WriteLine("Name: {0}", queryObj("Name"))
Console.WriteLine("TotalPhysicalMemory: {0}", queryObj("TotalPhysicalMemory"))
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
End Class
End Namespace

I've been searching online with no solid examples on how to integrate wmi calls into a vb.net web page.

View 1 Replies View Related

C# - Why Is SQL Query Returning Duplicate Results

Dec 1, 2010

The SQL is below - each result is coming up 3 times rather than just once.

SELECT Consignments.LegacyID, TripDate, CollectionName, DeliveryName, Pallets, Weight, BaseRate, Consignments.FuelSurcharge, AdditionalCharges, BaseRate * Quantity AS 'InvoiceValue', Consignments.Customer, InvoiceNumber,
WHEN child.LegacyID = Consignments.Customer THEN child.LegacyID
WHEN parent.LegacyID = Consignments.Customer THEN parent.LegacyID
ELSE this.LegacyID
END AS 'InvoiceAcc'
FROM SageAccount this
LEFT JOIN SageAccount parent on parent.LegacyID = this.InvoiceAccount
LEFT JOIN SageAccount child on this.LegacyID = child.InvoiceAccount
JOIN Consignments on (Consignments.Customer = this.LegacyID AND this.Customer = 'True')
OR (Consignments.Customer = parent.LegacyID AND parent.Customer = 'True')
OR (Consignments.Customer = child.LegacyID AND child.Customer = 'True')
WHERE (this.LegacyID = @Customer) AND (TripDate BETWEEN @fromdate AND @todate) AND (InvoiceNumber IS NOT NULL)

The SQL was given to me for another similar query, but this time I have modified it to try to use it for the query I'm doing now, so I'm assuming that I'm doing something stupid.

View 2 Replies View Related

LINQ-to-SQL Query Returning No Results?

Mar 5, 2011

I have a query using LINQ-to-SQL. It queries an underlying database table Rooms. It uses Where conditions to narrow down the results, namely:

Current Occupancy < Max Occupancy
Available Flag is Checked

I know this should return results but it keeps returning an empty set. Any ideas? Code is below

Dim selectedHalls = (From sh In dbHalls.Rooms _
Where sh.gender = Session("gender").ToString _
Where sh.max_occupancy > sh.current_occupancy _
Where sh.is_available = 1 _
Select sh.building_name).Distinct()

UPDATE: I've verified that the issue is with the statement where sh.is_available = 1, which doesn't make sense since this is a bit field.

View 3 Replies View Related

Access :: Using Results From A Sql Query In A Variable?

Oct 2, 2010

I've managed to use my MS Access database with repeaters and gridviews in my website. Basically, printing the result of a query directly to the website seems easy enough using something like this :


After quite a bit of googling this seems to be a common way to do this. My question then seems kinda silly.

I want to use some of the data from the query in for example a variable without sending the data to a repeater or gridview and so on. Say I just want the username and a password from a database and want to store the username in one variable and the password in another for further use in the code. What do I do?

View 1 Replies View Related

ADO.NET :: How To Alphabetise The Results From A Linq To Sql Query

Jan 26, 2011

I can't seem to change the order of the results coming back from a linq to sql query, I want just to return the distinct values from the field x.manufacturer in alphabetical order, this is what I have and it isn't working:

public IQueryable<string> Dropone()
return (from x in CAT.CatalogueDatas
where x.Parent == null
orderby x.Manufacturer
select x.Manufacturer).Distinct();

Currently I get the distinct values in non-alphabetical order, in fact I'm not sure what order they're coming out in, don't think it's the order in which they appear though.

View 5 Replies View Related

Output Query Results In HTML?

Mar 11, 2011

i query a database for retreiving all the columns. I will probably have many rows. Im trying to output the query results into an html table. This is what i have so far:


How could i store the many rows and output them using html as soon as i open a page?

View 3 Replies View Related

C# - Get Updated Query Results On Page?

Aug 2, 2010

I have an asp.net intranet site hosted on IIS on my computer.

On one page you can enter two user id's and get a side by side comparison of their roles in our (custom app) system.

I often use it to add roles when I'm setting up new users. After running the query, if i change a role and run the query again it will not show updated results. It's being cached somehow. I have to go to another page and come back and them run the query to get updated results.

How can avoid having to navigate away to get the updated query results displayed.n


View 2 Replies View Related

ADO.NET :: How To Get Results Of Query (single Value) Into A Variable

Jan 16, 2011

I have a Query which I run as an SQL. This is my SQL:

"SELECT COUNT(*) As NoDup FROM [XXX Dir] WHERE (FileName Like 'XXX_YYY_20100916.txt')"

The "XXX Dir" is a table and "FileName" is a text field within that table.

When I execute the SQL in the Query development windows, it returns a single value like 2.

I would like to assign that value to a variable so I can use it in my VB code.

View 1 Replies View Related

Access :: Query Returns No Results?

Aug 3, 2009

A strange issue here, I am using an ASP.net site with VB back end and an ACCESS 2003 database. I am trying to find all items whose serial number contains a string. I already figured out that access uses LIKE instead of CONTAINS, but now I have run into another strange issue.....Here is my Query: "SELECT ItemID,SerialNumber FROM TblItems WHERE SerialNumber LIKE @SN"then I add the parameter later: cmd2.Parameters.AddWithValue("@SN", "*" & TextBox3.Text & "*")When I copy and paste the Query into Access and run it (have to manually enter parameter, but i simply take what i put in the textbox and put a * on either end), I get the results I expect, however when the program runs, it returns no results.This is very confusing to me, why would the SAME query run in VB code return zero results while running SAME (copy and paste) Query in access do same thing?I have tried using non parametized query like this: "SELECT ItemID,SerialNumber FROM tblItems WHERE SerialNumber LIKE '*" & Textbox3.text & "*'" and same issue.

View 4 Replies View Related

Adding Results Of SQL Query To An IEnumerable String?

Aug 3, 2009

I'd like to put the results of a query into an iEnumerable string and I have no idea of the best way to do this.


View 4 Replies View Related

Web Forms :: How To Display Sql Query Results Dynamically

Jan 26, 2010

I want to display sql query results in my web application (asp.net webpage) dynamically at the run time. But I don't know how to do that. Is there any control to do that? Or is there any code? Could you give some examples?

View 4 Replies View Related

Avoid Error When No Results From Entity Query

Mar 14, 2011

I have a simple Entity query:


I then check whether one of the result values is more recent than six months ago using an if..then like so:

If rhcexists.First.SignatureDate > Date.Today.AddMonths(-6) Then
End If

However, if there are no results returned this will return an error. Is there a way for me to tell it to act as if the date is older than six months if there is no value at all? e.g., could I in pseudo do something like:

If Exists(rhcexists.First.SignatureDate, Date.Today.AddMonths(-8)) > Date.Today.AddMonths(-6) Then
End If

View 2 Replies View Related

Concatenating Results From SQL Query And NULL Columns?

May 11, 2010

I need to concatenate several columns of a table into a single value, then show that value in an asp dropdownlist. The SQL code I'm issuing is as follows:

SELECT UserID, CustomerNum, UserName + ' - ' + UserAddress + ',' + UserCity + ' ' + UserState AS UserInfo
FROM Users
WHERE (CustomerNum = @CustomerNum)

I then set 'UserInfo' as the text field in the dropdownlist.This generally works, except occasionally one of the columns in the database is null (for example, UserState). When that happens, the entire concatenation is null, and I get an empty entry in the dropdownlist.

Is there something in SQLServer that will allow me to ignore those NULL results, or will I have to code something up in the DataBind event?

View 6 Replies View Related

MVC :: Passing SQL Query Results From Controller To View?

Oct 16, 2009

What's the best way to run a sql query in a controller action and pass the results to a view to be databinded to a listview? I tried:


But it returns "No results" (the EmptyDataTemplate) every time, even when the query has results. Thus, I think something is wrong with the databind.

View 1 Replies View Related

Query - Use A Checkbox To Change The Results Of A SqlDataSource?

Feb 2, 2011

I'm using Visual Web Developer 2010 Express. This is my first attempt at creating a .NET page. I have a Gridview on a page that displays the results of a GridQuery. This works. I have a checkbox control(cb_Filter) on the same page that if checked, should add to the where clause of the GridQuery, (where Column5 IS NULL). How do I check the state of the check box so it will run the query with or without the "filter".

View 2 Replies View Related

C# - Use XMLHttpRequest To Execute A SQL Query And Return The Results?

Feb 9, 2011

I'm building a web app for my company that will run a query every few seconds against SQL Server, and the data that it returns is which database is restoring and how much % complete it is. I have the query already set up and it works fine.

What I want to do is on my Web Form, have a "div" element that will contain the % complete of a database restore, and have it update every few seconds using the JavaScript timer object:

setInterval(function, interval)

I figure I would need to use XMLHttpRequest to send the request to the web server which will run the SQL query. Am I on the right track? How would I even start to do this?

My SQL query is below:

Use master
Select der.session_id, der.command, der.status, der.percent_complete, *
From sys.dm_exec_requests as der
Where percent_complete > 0

View 1 Replies View Related

SQL Server :: Insert Query Results Into Table?

Feb 19, 2011


i want to insert the result of that query into nother table in my database. please help me find a way to do that.

View 2 Replies View Related

.net - Get Number Of Matched Results Of A Query To SharePoint?

Aug 1, 2010

I am using VSTS 2008 + C# + .Net 3.5 + ASP.Net + SharePoint Server Enterprise 2007 on IIS 7.0 with Windows Server 2008 Enterprise.

I am currently using queryex web serivces API to get matched query results for a specific query. My question is, how to get the number of matched query results without returning the whole query results? I only need the number of matched query results.


View 1 Replies View Related

Web Forms :: Display Results From Search Query?

Jun 8, 2010

I am developing a web form for search capability. The search query should return records from three different tables. How to display these three table records in three different rows. The search query should get the results from Table 1 and Table 2. Table 2 and Table 3 has a parent child relation ship. Which controls can I use for this purpose?

View 5 Replies View Related

DataSource Controls :: Validate Results Of A Query?

Jun 17, 2010

I am trying to find out if there are records in a table

based on the results of the query.

I have this that is not working

The query works but the problem is validating the resutls

MembershipUser myUser = Membership.GetUser();
Guid userIdPosts = (Guid)myUser.ProviderUserKey;
int currentThreadid = Convert.ToInt32(Request.QueryString["Threadid"]);
var query = from t in context.TrackLists
where t.UserId == userIdPosts && t.ThreadID == currentThreadid
select new { t.UserId, t.ThreadID };
foreach (var results in query)
Guid queryUserID = results.UserId;
if (queryUserID == null)

View 2 Replies View Related

Writing A SQL Query String Results To A Text File?

Jun 14, 2009

Is there an easy way of writing the results of a query string from sql into a text file via ASP.NET?

View 14 Replies View Related

SQL Reporting :: Query Designer Returning Different Results To SSMS?

Jan 29, 2010

I'm having an issue with SSRS 2008 inside VS 2008, where I have a report that is connected to the database via a Data Source which is working correctly, but when I execute a query inside the query designer to test my data, it returns zero records.

The issue I'm having is that the EXACT same query inside SSMS returns the correct record. I'm really stumped as to why it all is connected, but not returning the record. I have another report in the solution that uses the same database, but that one actually works ok.

View 5 Replies View Related

Forms Data Controls :: SQL Query Results Placed In Email?

Jul 29, 2010

(Mods, move if I put this in the wrong place) I'm running queries against SQL databases, and I'd like for the results of my searches to appear in table form in an email that is then sent out dynamically. I currently have the results appearing in a Datagrid on a webpage which I'm then manually transferring to an email form to send. I'd like to streamline the process so I don't need to do any manual entry.

How can I have a table/datagrid/whatever in an email that gets populated with the results of a SQL query?

View 1 Replies View Related

DataSource Controls :: Random Results From A LINQ To SQL Query?

Jan 23, 2010

I have this LINQ query:

var agnts = (from a in db.agents select new { a.userid, a.name }).Take(10);

How can I get randomly get 10 records from my agents table?

I have tried:

agnts = agnts.OrderBy(n => Guid.NewGuid());

but this doesn't seem to do anything.

View 5 Replies View Related

SQL Server :: Posting Results Of Query To Session Variable

Mar 22, 2011

I am having trouble getting a SQL query to post its results to a Session variable. I am close, but no success thus far. Here is what I have:

However, I keep getting this error when I click to a new page that is using this "PracticeID" Session variable: No mapping exists from object type System.Data.SqlClient.SqlCommand to a known managed provider native type.

View 5 Replies View Related

SQL Server :: Can't Save Query Results To Excel File?

Feb 3, 2011

I am executing the following T-SQL code, which runs successfuly according to message I see at end of its execution, but the file c:cptest.txt is never created. I have checked for this file and it doesn't exist. what is the issue here?

EXEC MASTER..xp_cmdshell 'bcp "SELECT top(10) from Person.Address" queryout "C:cptest.txt" -T -c -t,'

View 8 Replies View Related

Entity Query - Combine Into One And Avoid Merging The Results

Nov 6, 2010

I can't seem to figure out how to write this query properly. I've tried various combinations but nothing's worked yet. Below is the relevant portion of my database model: I need to select the products that match a given Category and Group, and that match a given Year, Make, Model, submodel. This I've done below:

ItemList = From P In gDataContext.Products.Include("Groups").Include("Groups.Category1").Include("LookupYearMakeModels") From G In P.Groups Where G.Category = Cat And G.Grp = Group From Y In P.LookupYearMakeModels Where Y.Year = YMM.Year And Y.Make = YMM.Make And Y.Model = YMM.Model And Y.Submodel = YMM.Submodel Select P

I now also have to select products that match the Category, and Group but are Universal (Product.Univeral = True). I'm currently writing two queries, the one above and the one below. I'm merging the results of the two by simply using ItemList.AddRange(ItemList2) ItemList2 = From P In gDataContext.Products.Include("Groups").Include("Groups.Category1") where P.Universal From G In P.Groups Where G.Category = Cat And G.Grp = Group Select P But I want to combine both queries into one and avoid merging the results. How can I do it?

View 2 Replies View Related

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