Skip to content

Using linq to SQL in ASP.NET with DAL

Dale Hermsen

Asked Nov 20, 2009, 7:16 AM EST4 answers
Share
LinkedInX
How do you get the data from an SQL Table using Linq by way of a Data Access Layer? I've seen numerous articles that show how to get the specific fields, but they all do console.writeline at the end. I want to bind the data to a textbox or label, or both. I can get 1 field OK by this: int numberfld = GetData.getRecord(ID); which calls the method in the DAL and returns the value. So, how do you go about returning the data for more than 1 column from the DAL so it can be used to populate any number of textboxes or labels? I've made it work using a foreach, but that seems like poor coding technique when I only want one row.

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You should check out the LinqToSql Business Object wrapper from West Wind Technologies. There is also a sample Asp.net app called TimeTrakker that you can download. http://www.west-wind.com/WebLog/posts/160237.aspx and http://www.west-wind.com/WebLog/posts/246690.aspx
    0
  • 0
    Thanks Matt, that was an informative article. I don't think I should have to go through that much code though just to pass data back from the DAL. When I execute the linq query in the DAL, I can see the various data elements and data, but don't know how to grab them when returning to the calling page.
    0
  • 0
    But the point is that the LinqToSql Business Object wrapper class that he has written handles all of that for you. All you do is create an object based on that class, and all that functionality is implelemted in you object. You don't have to write that code. HE has already done that for you. I already use this and it is very easy.
    0
  • 0
    But the point is he has already written all that code for you. All you have to do is create an object based off of his LinqToSql wrapper class, and all those methods will be handled for you. He has written all the code already. You can download his class lib and use it. It's very easy. I did it in my app.
    0