ADO.NET :: Check Not To Add 2 Entries In Db Using Linq?
Feb 10, 2011
have a button which add an entry to the database, but I don´t want to add the same entry twiceIs there a way to check using linq? something with .count? I´m kinda lost
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();
i included the table and its data as it would be impossible without that to understand. this is the meta scenario as you may notice that this was the query i wrote before when i was not checking the publish date
var postsidebar = from post in postrepository.GetAllPosts() join pstmt in postrepository.GetAllPostMetas() on post.int_PostId equals pstmt.int_PostId where (post.int_PostTypeId == 4 && post.int_PostStatusId == 2 && post.int_OrganizationId == layoutrep.GetSidebarDetailById(SidebarDetailsId).int_OrganizationId) && (pstmt.vcr_MetaKey.Contains(filter) && pstmt.vcr_MetaValue.Contains("true")) select post
how would i goint incoperate check for publish date in the query above( i want to bring all the records whose publish date is greater then todays date)
Using linq to entities i am connecting to a database, the database has tables in it that has payments that have a multi to multi relationship with jobs. This is acheived via an allocs table. I want a list box with all the jobs that has a column called due price which takes all of the allocations of payments for this job and takes that away from the job price. However, using the below linq to entities statement. The problem is that if the job has no allocations it returns null and therefore the due payment is empty. What i really want is for the due payment to be the job price if there are no allocations however, i cannot think of a way around this.
var jobs = from j in data.jobs where j.property.customer.id == customerid && j.completed != null select new { j.id, j.price, dueprice = j.price - ( from a in data.allocs where a.job.id == j.id select a.amount ).Sum(), lineone = j.property.lineone, postcode = j.property.postcode, jobtype = j.jobtype.name, j.completed };
1        Test1      abc     1000 2        Test2      dcf     1000 3        Test3      edf     1000 1        Test1      dcd     1000 2        Test2      dcf     1000
Now I want a linq query to check for the duplicate name and if present adding its rupees...
E.g.: Result will be
     name        rupees
     Test1        2000      Test2         2000     Test3         1000
I am using the TextBoxWatermark extender ASP.NET AJAX extender this works great, but i still want to have the comfort for my users, that the textbox remembers their entries e.g.:
Login=> TextBox with UserName
- if two people are using the same computer, they don't want to type UserName each time again instead click in the box and choose their UserName or start typing and their UserName is than suggested.
It seems to be a standard funktion that a TextBox remembers the entries you did. Unforantly when using the watermark extender on a textbox it simply does not work anymore.
Is there a way to enable this „feature" again?
When looking at the example of the TextBoxWatermark ASP.NET AJAX extender: [URL] it is not working their as well.
Suppose the form is to be submitted to Controller: Product, Action: Add. What sort of coding techniques can I use to handle this dynamic form, such that I follow good or best practice, and if possible also be elegant.
The solution I see so far is to test the Request.Form (or Formcollection) indexer/dictionary for existence for the dynamic input fields. E.g.
public ActionResult Add(Formcollection form) { int productEntry = 1; string productPrefix = "Product"; while(true) {........
I have a static class that holds a dictionary of objects. I have multiple threads that access this dictionary and create objects on it that are specific to that thread. How and when can I remove entries from the dictionary when a thread is "done"?
Basically this is a static class for an ASP.NET application that all requests can have "isolated objects" (that are related to the current thread) created in the dictionary. But, I don't really want to be tied to ASP.NET.
how am I be able to validate multiple entries (textbox control). It seems that using custom validate is not possible because each validator has one control to validate. In my case, I have to determine if at least one entry was filled with data.
I am getting an error whenever I try to get the first character from a textbox control when nothing was entered into it. So, I need to be able to check if there are any entries in a textbox before trying to get the first one.
I want to show just a 8 entries pro time, and above the table make some kind of navigation (like 1 2 3 4 5 ..) and if i need to see next 8 entries I#m clicking on the number 2, i see them. I dont know how can i do all this.
i working with mvc, and i want too that this solution is dynamic, that by more entries automaticly will have longer navigation 56 enties = (1 2 3 4 5 6 7).
I am using the built in database with the tables (i.e. membership, users, etc...). I created my own table (relationships), but when I try to create a row that uses the same email address it says "cannot create duplicate entries". I am not allowing duplicate email addresses in the membership table. That did not work because I couldn't convert System.Guid to long. So, I decided to do it by email address. I changed idRequester to requesteremail and the same for receiver. However, when I try another record with the same email address in either field, it does not accept it.
if i enter the value in the textbox based on the textbox value it should go to that page.for eg: i've one textbox,one buttonand three forms namely plant.aspx,green,aspx,companies.aspxif i enter the text as "what is plant" into textbox and click the button the it should search the word plant and redirect it to plant.aspx form.if i enter the text as "what actually green is" into textbox and click the button the it should search green and redirect to green.aspx form.
I'm wondering how to make a column that counts the number of entries like each entry that i made an is given an individual numbern the SQl Server it self
I'm creating a shopping basket in ASP.NET using session variables to pass the data from a shopping.aspx page to basket.aspx, currently I have the pages passing the primary key of the product with a gridview on the basket.aspx used to display the data from the database.However this only works for one item at a time, how can I extended the session variable so multiple products can be added, as well as quantities etc?
I'm using SqlMembershipProvider and SqlRoleProvider for user management.
Users are created by
Dim MCS As System.Web.Security.MembershipCreateStatus Dim NewUser As MembershipUser = Membership.CreateUser(TB_UserName.Text, TB_Pw.Text, TB_Email.Text, TB_SecQuestion.Text, TB_SecAnswer.Text, False, MCS) later, after email confirmation, I take the user into a specified role Dim myUser As System.Web.Security.MembershipUser = Nothing myUser = Membership.GetUser(New Guid(Request("RegID")))Catch If myUser IsNot Nothing Then myUser.Comment += " approved " Membership.UpdateUser(myUser) Roles.AddUserToRole(myUser.UserName, "role") End if
After this I have two entries with the same UserName in aspnet_Users table, but with different UserId's. One UserId is referenced in aspnet_Membership table and the other in the aspnet_UsersInRoles table.
I have a page which is using the AJAX Control Toolkit HTML Editor. I have it configured with only the Bold, Italics and Underline buttons. Once the user saves the information, it's stored in a database table. No problems.
I need to change the resulting code so the HTML code can be correctly interepted by a Crystal Reports report. CR doesn't understand the <span> options being created by the HTML editor. So for example, I need to change the
<span style="font-weight: bold">Bold</span> code created by the HTML Editor so it's entered into the database as <b>Bold</b> instead.
I can attempt this in the code behind, but I then also need to replace the </span> with a </b>. This causes an issue because if there are multiple options (e.g. bolded word within an underlined line), then the proper tags won't be closed as they should.