Click here to Skip to main content
16,012,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ERROR IS: "LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression."

C#
string  adID = txtSearchRegNo.Text;
//  int adID =Convert.ToInt32(txtSearchRegNo.Text);

var list = (from p in db.AdmissionDetails join s in db.StudentDetails on p.AdmissionId equals s.AdmissionId
            where p.AdmissionId==adID
            select new
            {
               RegNo = p.AdmissionId ,
               Student_Name = p.StudentFName +" "+ p.StudentMName +" "+ p.StudentLName,
               Mother_Name = p.MotherFanme,
               Cast = p.Cast,
               s.Nationality,
               Place_Of_Birth= p.PlaceofBirth,
               Mother_Tongue = s.MotherTongue,
               Date_Of_Birth = p.BirthDate,
             }).ToList();
Posted
Updated 16-Mar-15 23:54pm
v2
Comments
Santosh K. Tripathi 17-Mar-15 6:05am    
i would like to suggest to you "Place client side validation for txtSearchRegNo".
this will help to reduce error.

1 solution

Convert should not be your preferred way of getting an integer value from a user-input string.

User inputs should ba validated at all times. THe best way for that is to use the TryParse method. This way:
C#
int adID;
if (!int.TryParse(txtSearchRegNo.Text, out adID) {
   throw new ArgumentException("Entered text is not a valid integer representation.");
}
// Here you can make whatever you want with adID variable


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900