Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    ASP.NET


Advertisements:










C# - The Query Results Enumerated More Than Once?


datacontextclass dc=new datacontextclass ();
var news= dc.GetNewsCompany(Int64.Parse ( _idCompany));
if (news.GetEnumerator().MoveNext())
{
foreach (var item in news)
{
drpListNews.Items.Add(item.Title);
}
}

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

how can check result != null in LINQ;


View 3 Replies (Posted: Mar 17 at 9:28)

Sponsored Links:

Related Forum Messages For ASP.NET category:
MVC :: How To Get ModelMetadata For An Enumerated Type
I am having trouble getting the ModelMetadata for elements accessed through an IEnumerable type. Here is enough code to explain what I mean:

[code]....

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.

Posted: Nov 14, 2009 05:46 PM

View 3 Replies!   View Related
How To Add A Record To Query Results
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.

[Code]....

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...

Posted: Sep 22, 2009 04:48 PM

View 1 Replies!   View Related
Display Wmi Query Results In Web Page
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.

Code:

Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class MyWMIQuery
Public Overloads Shared Function Main() As Integer
Try
Dim searcher As New ManagementObjectSearcher( _
"rootCIMV2", _
"SELECT * FROM Win32_ComputerSystem")
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_ComputerSystem instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("Manufacturer: {0}", queryObj("Manufacturer"))
Console.WriteLine("Model: {0}", queryObj("Model"))
Console.WriteLine("Name: {0}", queryObj("Name"))
Console.WriteLine("TotalPhysicalMemory: {0}", queryObj("TotalPhysicalMemory"))
Next
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.

Posted: Apr 28, 2009, 09:10

View 1 Replies!   View Related
C# - Why Is SQL Query Returning Duplicate Results
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,
CASE
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.

Posted: Dec 1 10 at 14:18

View 2 Replies!   View Related
LINQ-to-SQL Query Returning No Results?
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:

Gender.
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.

Posted: Mar 5 at 16:14

View 3 Replies!   View Related
Access :: Using Results From A Sql Query In A Variable?
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 :

[Code]....

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?

Posted: Oct 02, 2010 10:03 PM

View 1 Replies!   View Related
ADO.NET :: How To Alphabetise The Results From A Linq To Sql Query
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.

Posted: Jan 26, 2011 11:06 AM

View 5 Replies!   View Related
Output Query Results In HTML?
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:

[code]....

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

Posted: Mar 11 at 2:40

View 3 Replies!   View Related
C# - Get Updated Query Results On Page?
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

[Code].....

Posted: Aug 2 10 at 19:49

View 2 Replies!   View Related
ADO.NET :: How To Get Results Of Query (single Value) Into A Variable
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.

Posted: Jan 16, 2011 06:25 PM

View 1 Replies!   View Related
Access :: Query Returns No Results?
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"thenI add the parameter later: cmd2.Parameters.AddWithValue("@SN", "*" & TextBox3.Text & "*")WhenI 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 runningSAME (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.

Posted: Aug 03, 2009 06:24 PM

View 4 Replies!   View Related
Adding Results Of SQL Query To An IEnumerable String?
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.

[Code]....

Posted: Aug 03, 2009 03:15 PM

View 4 Replies!   View Related
Web Forms :: How To Display Sql Query Results Dynamically
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?

Posted: Jan 26, 2010 04:49 AM

View 4 Replies!   View Related
Avoid Error When No Results From Entity Query
I have a simple Entity query:

[code]....

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

Posted: Mar 14 at 17:38

View 2 Replies!   View Related
Concatenating Results From SQL Query And NULL Columns?
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)
ORDER BY UserName

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?

Posted: May 11 10 at 14:54

View 6 Replies!   View Related
MVC :: Passing SQL Query Results From Controller To View?
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:

[Code]....

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

Posted: Oct 16, 2009 02:45 PM

View 1 Replies!   View Related
Query - Use A Checkbox To Change The Results Of A SqlDataSource?
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".

Posted: Feb 2 at 21:09

View 2 Replies!   View Related
C# - Use XMLHttpRequest To Execute A SQL Query And Return The Results?
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

Posted: Feb 9 at 18:52

View 1 Replies!   View Related
SQL Server :: Insert Query Results Into Table?
[Code]....

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

Posted: Feb 19, 2011 01:01 PM

View 2 Replies!   View Related
.net - Get Number Of Matched Results Of A Query To SharePoint?
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.

[URL]

Posted: Aug 1 10 at 16:51

View 1 Replies!   View Related
Web Forms :: Display Results From Search Query?
I am developinga 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?

Posted: Jun 08, 2010 03:11 PM

View 5 Replies!   View Related
DataSource Controls :: Validate Results Of A Query?
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)
{
}

Posted: Jun 17, 2010 10:42 PM

View 2 Replies!   View Related
Writing A SQL Query String Results To A Text File?
Is there an easy way of writing the results of a query string from sql into a text file via ASP.NET?

Posted: Jun 14, 2009 04:40 AM

View 14 Replies!   View Related
SQL Reporting :: Query Designer Returning Different Results To SSMS?
I'm having an issue with SSRS2008 inside VS 2008, whereI have a report that is connected to the database via a Data Sourcewhich is working correctly, but when Iexecute a query inside the query designer to test my data, it returns zero records.

The issue I'm having is that the EXACTsame query inside SSMS returns the correct record.I'm really stumped as towhy it all is connected, but not returningthe record. I have anotherreport in the solution that uses the same database, but that one actually works ok.

Posted: Jan 29, 2010 02:38 AM

View 5 Replies!   View Related
Forms Data Controls :: SQL Query Results Placed In Email?
(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?

Posted: Jul 29, 2010 10:44 AM

View 1 Replies!   View Related
DataSource Controls :: Random Results From A LINQ To SQL Query?
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.

Posted: Jan 23, 2010 07:12 AM

View 5 Replies!   View Related
SQL Server :: Posting Results Of Query To Session Variable
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:
[Code]....

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.

Posted: Mar 22, 2011 06:24 PM

View 5 Replies!   View Related
SQL Server :: Can't Save Query Results To Excel File?
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,'

Posted: Feb 03, 2011 04:31 AM

View 8 Replies!   View Related
Entity Query - Combine Into One And Avoid Merging The Results
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?

Posted: Nov 6 10 at 6:47

View 2 Replies!   View Related
Sql - Dynamically Generating Buttons Based On Query Results
I am trying to add some filters to a gridview that I am working on, and I'm wondering if it is possible to generate links or buttons above the gridview based on the years returned in the dataset. For example, if my dataset contains dates from 2001, 2009, and 2031 in my date column, I would like to be able to take that data from my SQL query (getting a distinct list of years is not an issue), and generate the buttons. From there, I would filter the data in the gridview based on the user clicking the buttons.

Is dynamic generation of buttons possible in ASP.NET? I do have some other ideas of how to accomplish the same functionality, but I would prefer to do it this way.

Posted: Dec 20 10 at 21:48

View 1 Replies!   View Related
DataSource Controls :: Showing Query Results In A Textbox?
Lets say Ihad aquery like SELECT Name FROM Customers WHERE CustomerID = '1'

How could I show the result in a textbox?

Posted: Jan 08, 2010 03:09 PM

View 3 Replies!   View Related
MVC :: Unable To Show Linq Query Results In View?
I perform a Linq query in the controller but get no intellisense for the For Each display in the view, I''ve imported he namespace and done a ctype to IEnumerable on the results which seems to be all that's required according to various tutorials and videos.

[Code]....

[Code]....

Posted: Dec 15, 2009 05:30 PM

View 2 Replies!   View Related
DataSource Controls :: Email Query Results Formatting?
I have a SQL server job that executes msdb.dbo.sp_send_dbmail procedure and sends an email. I have specified the query and the query results appear in the body of the email as expected. All i need to know is how to remove the dashes beneath the column names. For instance, when Ireceivethe email with the query results, they look like the following

UserId UserName

1 Rob
2 Paul

How do I remove those dashes underneath the column names?

Posted: Feb 25, 2010 11:13 PM

View 3 Replies!   View Related
Use An If Then Statement To Display Different Images Based On Query Results?
I am a network/voice guy who has a monitoring system that inputs data into SQL 2005 database. Using Visual Web Developer 2008 Express, I have built pages that return query results from this database and these are nested pages with a number of master pages. But now I'm at the point of trying to figure out how to return different images for the query results like I did using another product which had its own scripting language. I would write a statment like 'if query1 = 70 then img=70.gif else query1 = 80 then img=80.gif. I have read on multiple sites that one would use a asp:TemplateField for the image and then 'code behind' for the If..then..else. What exactly is 'code behind'? Some sites say make the code behind a .dll, while others don't state what to make it. What should this code behind be saved as? How would one reference the value returned in the GridView?

And some sites state to reference it in the <%@ Page Language="VB".....%> line, but that is where the Master page is referenced. Can they both be referenced here?

<%@ Page Language="VB" MasterPageFile="~/Overall_sub1.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="monitoring" %>

Is there a video or white paper that I can review?

Here is one of the queries:

<asp:Content ID="Content4" ContentPlaceHolderID="MainContent3" Runat="Server">
<div style="height: 30px; width: 380px">
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" GridLines="None"[code]....

Posted: Oct 28, 2009 07:06 PM

View 2 Replies!   View Related
DataSource Controls :: Writing A Query Filter That Gets All Results For That Day?
i have a "Users today" function that i am trying to work on, i have all the tables set up, and a TimeStamp column, i would like to know how i could get all the users that appeared, but for that day only.

So i used the select statement, but then when i tried to add into query, filtering, i tried using the DateTime.Now, but it only got the users specific to that date, hour, and second.

Posted: May 11, 2010 12:10 PM

View 3 Replies!   View Related
Forms Data Controls :: Binding SQL Query Results To A Gridview?
I have a gridview that I want to bind the results of a query to it once a user selects a value from a drop down list.

The query selects the same row from the same table but selects different fields based on the drop down list value selected

I get to the query selection but it does not refresh that page with the populated gridview.

Here's the code behind code

protected void ddlQuantity_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection connection = null;
connection = new SqlConnection(ConfigurationManager.ConnectionStrings["PSI_DB_1ConnectionString"].ConnectionString.ToString());
connection.Open();
String nEstno = Request.QueryString["id"];
int id = Convert.ToInt32(Request.QueryString["id"]);
string SQLquery = "";
switch (int.Parse(ddlQuantity.Text))
{
case 1:
SQLquery = "Select Quan1"etc...;
break;
case 2:
SQLquery = "Select Quan2"etc...;
break;
case 3:
SQLquery = "Select Quan3"etc...;
break;
case 4:
SQLquery = "Select Quan4"etc...;
break;
case 5:
SQLquery = "Select Quan5"etc...;
break;
}
SqlCommand Cmd = new SqlCommand(SQLquery, connection);
SqlDataReader Dr = Cmd.ExecuteReader();
if (Dr.HasRows)
{
gvEstQty.DataBind();
}
Cmd.Dispose();
connection.Close();
connection.Dispose();
}

Posted: Aug 11, 2010 04:15 PM

View 2 Replies!   View Related
Forms Data Controls :: Want To Databind The Results Of The Query To A Listview?
I have a 2 table dataset created from a access database. I have written a query against the dataset which requires a parameter and returns mutiple records, but only a single field (PublicationName). I now want to databind the results of the query to a listview.I have written the following code in the page_load event, but it is throwing up an error, can anyone else

Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

[code]...

Posted: Sep 27, 2009 06:35 PM

View 7 Replies!   View Related
Security :: Using Membership To Filter Query Results / View/ Reports?
I am developing this website which requires multiple groups of roles inside membership. Here is an example:
I want to create a group of states (would be the first group of roles):

* Oregon
* California
* Kansas
* Texas
* Ohio

Then I want to use the membership provider to filter the query results. Example:

* Patrick is an website admin and he can view all states from the query results

* Laura is from Kansas, so she can view only Kansas results from the query (reports, submission form only to Kansas, and so on..

Posted: Nov 16, 2010 03:55 PM

View 5 Replies!   View Related
SQL Server :: Disable Query Results Window While Running A Script?
I am running a sql script which Inserts 500 rows and after each insert, it calls a stored procedure which diplays result in the results window. So after executing 100 rows, it throws an error that maximum number od results in the results pane has reached its limit but the query executes successfully. How can we disable the stored proc output to not display in the results pane. I do not have access to the stored procedure.

Posted: Oct 21, 2010 04:26 PM

View 4 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved