DataSource Controls :: Get Sum In Single Query?
Jan 4, 2010
I have 2 tables table1 and table2 as given below.
Table1 - user master table. table2 - transaction table. Now I want to write a single query which will give results like table 3. how to write single query.
TABLE 1
TABLE 2
TABLE 3
USER ID
[Code]....
View 13 Replies
Similar Messages:
May 25, 2010
For context: First of all, I am new to LINQ, as I have been using SubSonic for quite some time now.
I have two tables, Users, and Affiliates. They both have a very typical schema. The FK that joins them is the UserId field, which is in the Affiliates table. I want to create a LINQ query that pulls the Username from the Users table using the AffiliateId value. The AffiliateId is a primary key of the Affiliates table.
I have tried to accomplish this using many variations of the following code:
[Code]....
In the above query, I expect to get a single row result set. However, I instead receive the entire table of results.
How can I make this work? I have yet to see an example or article out there to do what I am trying to do.
View 9 Replies
Jan 15, 2010
I am using a 'SingleOrDefault' LINQ query with a Lambda expression such as:
Email email = db.Emails.SingleOrDefault(p => p.Email1 == Textbox1.Text);
If the textbox entry does not match anything stored in the table, how would I know and how could I deal with this situation in the code?
View 12 Replies
Aug 22, 2010
1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like
SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.
Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).
2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query
(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).
If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.
View 11 Replies
Jan 15, 2010
[code]...
This query works perfectly on the query analyser.
But when configuring the Table adapter ,I try executing the query and i get 0 rows affected.
What could I be getting wrong in this case.
NB:Existing GalleryID has been supplied.
View 1 Replies
May 17, 2010
By right clicking on my database i created a query in server explorer. But where are this query stored can't find them back. I should aspect that their is a folder query's like there is a folder tables but this isn't the case.
View 10 Replies
Mar 10, 2010
select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid
View 5 Replies
Jan 21, 2010
I've got a query such as
Dim MediaQuery =
From m
In dB.DOWNLOADS _Where m.ID = id _Select
which returns a record from the database. One of the fields in the record is a FK to another table. I need to read this value to be able to set a dropdown based on the ID but I can't work out how to access it. For a standard record I can just do the following txtTitle.Text = MediaQuery.FirstOrDefault().TITLE
However with the foreign key it doesn't work like that. I've tried drpGroup.SelectedIndex = MediaQuery.FirstOrDefault().DOWNLOAD_GROUPS.ID where DOWNLOAD_GROUPS is the FK field but it returns Object reference not set to an instance of an object. If you're simply wanting to read some values from a single db record in the entitiy framework and one is a foreign key how should I go about getting the value?
View 2 Replies
Feb 5, 2011
I wanted to know is it possible to pass "SqlDataSource" data to a variable? if not how can i use datareader to do this?
i couldn't figure out how to pass SqlDataSource to a varialbe so i tried use datareader and i'm stuck in middle of it, also my query only returns one row and one column so i rather not to use array if possible. here is my code:
[Code]....
View 3 Replies
Jun 23, 2010
I have 2 tables. Table_A has one to many relationship with Table_B.
For example. Table_A has an ApplicantKey and in Table_B I am storing (Resume_name and CoverLetter_name for the Applicant). Joined by ApplicantKey
Now when I join them and execute the query obviously it returns me two rows. But what I want is that it should return only one row with Columns like Resume_name, CoverLetter_Name
View 2 Replies
Jul 2, 2010
i develop a c# windows application. My database is sql server 2008 exp. i want lock single row for user select it for update. for example;
userA - Connection a (connection id 52);
user select a single row (select * from t1 with(rowlock?, updlock?,or what) where id=1) and bind data to form fields (texbox, checkbox,combobox etc.). (there is no problem)
userB - Connection b (connection id 54);
userB can select all other rows from t1 (where id=2 or 3 or anything) but not id=1. when userB select * from t1 where id=1 system generate an exception with (you cannot select this row because it is updated. Updated users connection id is 52.)
when userA (connectionid52) close form or commit changes then userB can select id=1.
i am read few documents (transacions, rowlock,updlock, concurrency violation optimistic,pessimistic) but i couldn't understand.
View 1 Replies
May 25, 2010
I need to get one record from rows. For example:
DB:
id, name, age, nick, gender , etc...
1, John, 18, gobb, M, ....
2, Andrew, 22 , AND, M, .....
3, Simon, 35, Lucky, M, ......
How to Get name (For example Simon) from DB and enter it into label? Or perhaps this is impossible?
View 2 Replies
Feb 18, 2010
I've managed to connect to the database and return a record based upon a login name. I can itterate through the rows printing out the password but I know there's only 1 row (or can test for that) so how do I get the value of the password for the one row without the loop?
Dim supervisorAdapter As New SupervisorTableAdapters.SupervisorTableAdapter
Dim supervisors As Supervisor.SupervisorDataTable
supervisors = supervisorAdapter.GetSupervisorByLogin(login)
For Each count As Supervisor.SupervisorRow In supervisors
Response.Write(count.password)
Next
View 3 Replies
May 18, 2010
I have a table in which a field consists of a multiple values like CSE, INF, ECE etc., I want to take only one value from the field like
When an user selects a particular branch like CSE, the user should get the list of Colleges assosiated with the branch CSE. How to do this?
View 3 Replies
Jan 15, 2010
How can I filter two different datatable in a single dqatatable? like consider I have following two datatables
DataTable A DataTable B
PID | CID CID | FID
1 | 1 1 | 1
2 | 2 4 | 8
4 | 16 16 | 32
So after filtering I can have a output like
DataTable C
PID | FID
1 | 1
4 | 32
So in my filtered dattable I can have only matching results of datatable A and Datatable C? How can I do this using .Net datatable?
View 4 Replies
May 2, 2010
I'm working on my private website(using VS2008) which is connected to a simple database(using SQL management studio 2008). The database is currently located in the App_Data folder and the connectionstring should be quite simple;
[Code]....
After reading several forum threads I have changed the following;- Permission (locating the db and going into security, removing current users and adding me (local) to it as single owner on both .mdf and log file.
View 2 Replies
Sep 8, 2010
This works great for 1 parameter
SqlDataSource1.SelectParameters("City").DefaultValue = Me.Page.Title
But I can't figure out how to pass in two parameters in a single statement (See the Select Parameters Below) Two paremeters (City, and Classification) If I set the page title to say "Bismark Charters" Bismark = City & Charters = Classification
[Code]...
</SelectParameters >
View 4 Replies
Mar 24, 2010
i have a command like
SQLCommand cmd = new SQLCommand("insert into customers name values ('"+textbox1.Text+"')",conectionstring);
cmd.ExecuteNonQuery();
now when people enter a (') single quote, this doesnt work. how do i avoid this error as this is driving me nuts!! i cannot prevent users from entering single quotes as names like "O'Connor" contain a single quote. parameterized query doesnt seem to be the best solution as it involves loads of coding and will involve huge changes in the code. as its not a fresh app im making... can some modification in the code above so this can be avoided?
View 8 Replies
Mar 27, 2010
I've tried:
[Code]....
I've also tried:
[Code]....
View 5 Replies
Feb 2, 2010
Iam Facing the problem with Insert query in sql Server i want to insert value India's, Iam not unable insert 's in sql server DB.
View 17 Replies
Jul 16, 2010
I'm attempting to hook up multiple DropDownLists to a single SQLDataSource, but I want the SQLDataSource to return different rows depending on which DropDownList it is populating.
Say I have a table full of names (we'll call it TABLE_NAMES):
[code]....
....and I have two dropdown lists, one with a list of person names and one with a list of dog names.
Is there a way to link up each of these dropdown lists to a single SQLDataSource and use the SelectParameter to differentiate between which records I want returned for each dropdown list?
To make matters worse, these dropdown lists will appear within a GridView control....so there will be multiple instances of each dropdown list depending on how many rows there are in the GridView.
View 1 Replies
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
Aug 18, 2010
i want take a single value result from linq query
if i have :[Code]....
the variable result does not return nothing, only tostring() and similar how can i get a single result from linq query and use it in my ID variable?
View 1 Replies
Sep 28, 2010
I have an ASP.NET page which takes a number of parameters in the query string:
search.aspx?q=123&source=WebSearch
This would display the first page of search results. Now within the rendering of that page, I want to display a set of links that allow the user to jump to different pages within the search results. I can do this simply by append &page=1 or &page=2 etc.
Where it gets complicated is that I want to preserve the input query string from the original page for every parameter except the one that I'm trying to change. There may be other parameters in the url used by other components and the value I'm trying to replace may or may not already be defined:
search.aspx?q=123&source=WebSearch&page=1&Theme=Blue
In this case to generate a link to the next page of results, I want to change page=1 to page=2 while leaving the rest of the query string unchanged.
Is there a builtin way to do this, or do I need to do all of the string parsing/recombining manually?
View 4 Replies
Jun 26, 2010
After creating a dataset, which has CRUD statements generated two or more tables, which Data Control should I use that will allow me to insert data into fields into 2 or more tables from a single web form. I'm trying to create a web form that will allow the user to input student information, such as general information, medical information, etc.
View 3 Replies