ADO.NET :: How To Check If The Tables Has Rows In Linq
Nov 23, 2010
I am very new to Linq , i want to check if the PrintingAdminSetting table has rows in it and then if it has then i want to get the value and assign it to txtMaxJobs textbox
below is teh code
, please let me know teh syntax to check .
var DC = new ServiceDataContext();
var rec = DC.PrintingAdminSetting.Where("").First();
txtMaxJobs.Text = rec.ParaName.ToString();
View 4 Replies
Similar Messages:
Mar 21, 2011
I have been handling everything in code which is not working consistently same in all scenarios.
View 1 Replies
Jun 17, 2010
[Code]....
In above query I want to have top 10 rows as well as count of all rows.
View 3 Replies
Dec 14, 2010
I need to copy rows for 2 tables from one db to another.I want to be able to do identity insert, one way is to change the column to not be PK.if I mark the pk not a pk but just a column, can I still map it as an ID?
View 1 Replies
Sep 29, 2010
I am having trouble deleting three table rows using SQL. The middle table is a junctional table allowing a one to many relationship between table 1 and table 3.
Table 1
Order_Id int Primkey FK1
Name Varchar
Date Datetime
Table 2
Order_Id int PrmKey FK1
Item_Id int PrimKey FK2
Table 3
Item_Id int PrimKey FK2
Description Varchar
Price money
Acually, I want to delete all rows associated with any particular order.
View 3 Replies
Jul 24, 2010
I am accessing rows in an SQL database table based upon the contents of the Primary key and another column. But, I cannot insert new rows in the table when the content of the new Primary key column already exists in another row. Can I define the table with a multiple column Primary key so that a unique value can be based upon the content of both columns?
View 3 Replies
Jan 8, 2011
im currently doing a web form that shows will show the contents of a table from a database... the problem is that the codes im using only shows the data from the 1st row of the table and i need the data from all the rows of the tables
using System;
using System.Data;
using System.Configuration; [code].....
View 6 Replies
Apr 13, 2010
I have a problem where I would like to get a comma-separated list of items from a couple of tables as part of a set of results. All the searching I've done so far has produced results for dealing with one or two tables. I have four, and can't get my head around how to adapt the sql to deal with it.
I have the following layout:
*Table_Castings*
+---- CastingID {PK}
| MouldID
| SerialNo
| CastRef
| MeltCode
| Signature
|
|
| *Table_CastCertificates* *Table_Certificates*
| CertificateID {PK} ----------- CertificateID {PK}
+---- CastingID {PK} Description
FileID -----------------+
|
|
*Table_CertificateFiles* |
FileID {PK} -------------+
FullLocation
The results I would like include the following columns:
CastingID, MouldID, SerialNo, CastRef, MeltCode, [Certificates],
Where Certificates is a comma separated list of Description + " " + FullLocation records. (What I'll actually do is add http:// and other html codes to make FullLocation a hyperlink, but I can do that.)
Some SQL I've already got is this:
DECLARE @str VARCHAR(500)
SELECT @str = COALESCE(@str + ', ','') + '<a href="http://' + Table_CertificateFiles.FullLocation + '">' + Table_Certificates.Description + '</a>'
FROM Table_CastCertificates INNER JOIN
Table_Certificates ON Table_CastCertificates.CertificateID = Table_Certificates.CertificateID INNER JOIN
Table_CertificateFiles ON Table_CastCertificates.FileID = Table_CertificateFiles.FileID
WHERE (CastingID = 45)
SELECT output = @str
This actually gives all records in the for the specific casting, but I keep getting an error at the "=" in @str = COALESCE when I try joining it to another query to get each casting.
View 3 Replies
Jun 17, 2010
[Code]....
View 2 Replies
Feb 22, 2011
I create an one webpage in asp.net all the time i am facing the following pbm how to rectify it..
if(ds.Tables[0].Rows.Count > 0)
View 2 Replies
Jan 24, 2011
I need to make a category filter. For this purpose I have two tables "Ingredient" and "Category"
My Category Table looks like this:
[Code]....
And my ingredient table:
[Code]....
I want to join the two tables so when the KategoriID match it should then return all from that category.
[Code]....
[Code]....
View 2 Replies
Sep 9, 2010
I was trying to find out how I can join more than 2 tables using the LINQ-to-SQL syntax. For instance, joining 2 tables in SQL:
SELECT * FROM Table1 AS T1 INNER JOIN Table2 AS T2 ON T1.Key=T2.Column1WHERE T2.Key='17';
can be expressed as:
var Result = from T1 in DbContext.Table1 join T2 in DbContext.Table2 on T1.Key equals T2.ForeignKey where T2.Key=17 select new { T1, T2 };
But how would I join 3 or more tables using LINQ? For example:
SELECT * FROM (Table1 AS T1 INNER JOIN Table2 AS T2 ON T1.Key=T2.Column1) INNER JOIN Table3 AS T3 ON T3.Key=T2.Column2 WHERE T2.Key='37';
I've been searching and experimenting and I cannot seem to find any informraiton on this. One example I found involves putting the result for the frist join into a temp object, and then performing the second join. I'm not sure performance-wise if that's the same as doing a 3-table join directly using a single SQL statement.
View 4 Replies
Apr 12, 2010
i have a job application process where users apply for a job, in the admin section administrators want to be able to see which applications have not been viewed. Now i have one page which lists all the job vacancies and then users can click into that specific vacancy to see which people have submitted an application. This all works fine.
However on the page i display the job vacancies i need to make it so that if there are any applications within a vacancy that need viewing it appears in RED.
The two tables i am using are below:
tbl_vacancies
job_id
job_name
location
voucher
details
availability
region
date_added
tbl_applications
application_id
job_id
fname
sname
other_info
.
.
.
.
date_addedd
viewed
Now the viewed column is in tbl_applications table, the applications relate to a specific vacancy via the job_id.
So what i need to check is IF there are ANY applications where the viewed = 0, if so that means that there are applications that need to be seen, and i want this to appear in RED.
Now i tried this several ways i.e an INNER JOIN etc.. but the full list of vacancies won't appearing.
So i tried this:
[Code]....
[Code]....
This doesnt work at all. I have a datareader which runs through the returns, i don't get any errors, and the applications display correctly but when i use the IF to check it doesnt work..
View 2 Replies
Jul 21, 2010
I have 3 tables
Restaurants
IDNameAddress
Location
ID (Foreign Key)LocationID
Food
ID (Foreign Key)FoodID
Here's what I want to do, I have two variables @FID(food ID) and @LID(LocationID). I want something like
select * from restaurant where ID in (( select ID from location where locationID = @LID) AND (select ID from Food where FoodID = @FID))
The bold part is where I'm having problems. I want it to check both the Location and Food table for a match.
I'm having a hard time putting it into words :p I hope you get what I mean
View 2 Replies
Mar 12, 2011
I have 5 tables as follows
as it can be seen from diagram, I have one table ie.patientdetails with Pid as primary key and other 4 tables have pid which is foreign key related to Pid in patient details.
the problem is that when if a test data is filled for say patient with Pid as 1, the data is saved nicely in required tables
If i try doing that again for same patient then a duplicate is created in test tables with pid as 1.
View 7 Replies
Feb 13, 2010
Im having a go at doing a report for my asp.net application. I have 2 tables, one which lists a loan we have given to a customer, and another table which lists repayments against the loans.
I want to display each loan and how much is outstanding against it. My problem is that each loan is repeated in the table for each repayment against it. So when i try to sum up the loans awarded to a customer, if they only have one loan and have made 3 repayments against it, it sums up the amount awarded against each record.
eg, if i award a customer a loan of £200, and they make 3 repayments of £50, 3 records appear in the table. The amount awarded is repeated against each repayment, and when i total a customers loan amounts, it totals 3 x £200.
I have put the details into the grouping row, where it is grouped by loan_id, displaying the toal of repayments instead of each repayment. This stops it repeating in the table, but when i total the amount awarded field it still calculates 3 x £200.
I tried calculating the total on the report item after grouping but you cannot calculate on a report item.
Is there a way to stop the table from repeating the amount awarded against each repayment? Or even a way in the SQL statement of the dataset to make it display a total of repayments rather than each repayment. Cant see how to calculate a total repaid as i would need to pass a Loan_id in as a parameter.
View 3 Replies
Sep 4, 2010
I am using VS 2010 I've created LiNQ .dbml file via .. Model>Add New Item>Data>LINQ to SQL Clases I've put table on designer surface using drag & drop. I've done all this from one tutorial. There Is Mapping with arrows between tables in tutorial. How can i do this?
View 2 Replies
Aug 17, 2010
I have a partitioned db where several tables have the exact same structure. I'm able to query the tables using linq, but only by quering the individual tables 1 at a time and by using the explicit table name. For example at the moment, I have 8 tables so I have something similar to the following:
[Code]....
Is there any way, that based on a certain value (stringValue), I could determine which table to query and then code the linq query just once?
View 2 Replies
Mar 23, 2011
I have two tables:
Entity
ID (PK), int
Name
Descrip
Users
ID (PK)
EntityID, int (this is not connected to Entity table)
Now I am using LINQ to pull the records which has a Entity.ID = something. Which will show me couple of records in my GridView. Here is my LINQ statement:
protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryString["EntityID"];
int getIntEntity = Int32.Parse(getEntity);
OISEntityTestingDataContext db = new OISEntityTestingDataContext();
//OISLinqtoSQLDataContext db = new OISLinqtoSQLDataContext();
var tr =
from r in db.Users
join s in db.Entities on r.UserID equals s.ID
where s.ID == getIntEntity
select new
{
//To Show Items in GridView!
};
GridView1.DataSource = tr;
GridView1.DataBind();
}
Now here I am getting an error mesg on 'join' The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join What does that mean?
View 3 Replies
Dec 9, 2010
I have T_articles to save the articles.
each article has authorCode , and categoryCode.
each article can be modified by the author several times.
and I save every modification in the T_articles in a difference row.
now I want to dislpay for each autor:
author name, article name , article category's name, last modified date
In SQL I should to it like that:
[Code]....
I try to write it in Linq so:
[Code]....
so I got error:
[Code]....
and again I got an error:
[Code]....
View 4 Replies
Aug 12, 2010
I have a couple tables that are kind of unrelated - id like to search through both of them and create a type that i can sift through later
something like this doesnt work
[Code]....
I basically want to create a list of "AnimalSearchResults" that contains all dogs and all cats that have that name Whats the best way to do something like this?
View 6 Replies
Nov 9, 2010
Here's my DB structure:
I have three tables.
User, Details, Optional
User has fields: ID, FirstName, LastName
Details has fields: ID, MyDetails1, MyDetails2, User_ID
Optional has fields: ID, MyOptions1, MyOptions2, User_ID
There is a 1 to many relationship with User & Detail (User ID & Detail User_ID)
There is a 1 to many relationship with User & Optional (User ID & Optional User_ID)
With that said, one user can have many details and/or many optionals
Now I'm trying to build a linq query that will say:
"where user id = x, select FirstName, LastName, all MyDetails1 from every record where User_ID == x, all MyOptions1 from every record where User_ID == x"
After the merge I should have one string that lists the distict user & all of their many fields:
FirstName + LastName + (MyDetails1 + MyDetails1 + MyDetails1..etc) + (MyOptions1 + MyOptions1)
Anyone try this before?
I tried this with JOIN but this doesn't do the trick for what I'm looking for.
So if I had 3 MyDetails records associated with ID == 2, I would get three results like:
John Doe MyDetails_X
John Doe MyDetails_Y
John Doe MyDetails_Z
View 1 Replies
Aug 8, 2010
Using Linq to Sql how do i group the following 2 tables.
Orders Table:
CustomerID | Name |Date
1 | order1 | 2010-01-01
2 | order2 | 2010-01-01
2 | order3 | 2010-04-01
Calls Table:
CustomerID | Name |Date
1 | call1 | 2010-01-01
3 | call2 | 2010-06-01
2 | call3 | 2010-05-01
I want to group the two tables by date , Result:
Date | Orders | Calls
2010-01-01 | 2 | 1
2010-04-01 | 1 | 0
2010-05-01 | 0 | 1
2010-06-01 | 0 | 1
i know how to group a single table ,from o in Orders group o by o.Date.Date into og select new {Date = og.Key,Orders= og.Count()};
View 2 Replies
Jan 8, 2011
The main problem is that I recieve the following message:
"base {System.SystemException} = {"Unable to create a constant value of type 'BokButik1.Models.Book-Author'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."}"
based on this LinQ code:
[Code]....
How shall I solve this problem to get a class instance that contain with property title and Book-AuthorID?I also have tried making some dummy by using "allbooks" relation with Code Samples from the address
http://www.hookedonlinq.com/JoinOperator.ashx. Unfortunately, still same problem.
I also have taken account to Int32 due to entity framework http://msdn.microsoft.com/en-us/library/bb896317.aspx. Unfortunatley, still same problem.
Using database with 3 tables and one of them is a many to many relationship. This database is used in relation with entity framework
Book-Author
Book-Author (int)
BookID (int)[code]....
View 1 Replies
Sep 9, 2010
I was wondering how Linq to Sql determines which tables to write to when given primary/foreign Key relationships. I can (hopefully) better explain using an example. I have the following tables:
Customer CustomerStatus CustomerType CustomerAddresses
Therefore I have a Customer Entity, a CustomerStatus entity, a CustomerType Entity and a List of CustomerAddresses. In my code, I load up the Customer Entity and the List of CustomerAddresses because that's all I need. For some reason Linq to Sql is trying to insert a new Customer Status record. I have no idea why its doing this.
Can anyone please explain to me how linq to sql determines which table(s) will be written to based on the entities above?
View 5 Replies