Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 13th, 2012, 02:33 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 38 - Using Linq to Sql with Access

I seem to be unable to duplicate building the "Customer Table". When I open the toolbox and click on Class, I get a class object with no records in the class.
Please elaborate on the procedure on Page 438, if it is relevent for a Access database, and Page 432 para.4 and beyond.

I am using Visual Studio 2010 and MS Access 2010.

Thanks for you help

Warren Crowe
Reply With Quote
  #2 (permalink)  
Old January 20th, 2012, 01:47 PM
Rod Stephens's Avatar
Wrox Author
Points: 2,726, Level: 21
Points: 2,726, Level: 21 Points: 2,726, Level: 21 Points: 2,726, Level: 21
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jan 2006
Location: , , .
Posts: 566
Thanks: 1
Thanked 75 Times in 74 Posts
Default

Sorry for the slow reply.
I seem to be unable to duplicate building the "Customer Table". When I open the toolbox and click on Class, I get a class object with no records in the class.
Please elaborate on the procedure on Page 438, if it is relevent for a Access database, and Page 432 para.4 and beyond.
Do you mean page 428 instead of 438? I think that code should work after you create the LINQ to SQL classes for your database not matter what kind of database it is.

That code:
  1. Creates a data context to represent an attachment to the database.
  2. Creates a new Customer object.
  3. Calls the context's InsertOnSubmit method to get it ready to add the new record.
  4. Calls the context's SibmitChanges method to make the addition.

If that's not the code you're looking at, let me know.

The Customer class represents records in the table. If you create a new instance of the class, you're creating an object that *could* be stored in the table but it has not been stored there yet. You need to call InsertOnSubmit and SubmitChanges to add the new record to the table.

You should be able to use LINQ queries to get records from the table as shown on Page 429. The data context provides access to the tables. For example, the second piece of code on page 429 selects data from db.Customers. This is the Customers table in the database.

Normally you would build the database and its tables, possibly with some initial data, in a database tool such as Access or SQL Server's Management Studio. I'm pretty sure that's what I did.

To set up for using Access, follow the steps on page 432. They are briefly:
  1. Create a new project.
  2. In the File menu, select Add New Item, select "LINQ to SQL Classes," and click OK.
  3. Add a class object to the designer. Initially it has no fields. Right-click on it and select "Add Property" to add a properties such as FirstName, LastName, or whatever you want in the class. These should match the fields in the database table. For example, if this is a Customer class, make it match the Customers table.
  4. Click on the class's properties and use the Properties window to set the properties of the properties. For example, set Nullable, PrimaryKey, Server Data type, etc.

When you're done creating the classes, then I think you can use code similar to what's shown on Page 433 to connect to the database.

I hope that helps but I'm not sure if I've answered your question. If not, post again to let me know where you're stuck and I'll try to provide more detail.

(BTW, if you're going to do a lot of this in real applications, as opposed to just for learning purposes, then you might want to consider installing SQL Server Express Edition. It's a little harder to administrate than Access but it uses Microsoft's preferred database connection methods so a lot of the code works more easily with it than with Access and other database types. And SQL Server Express Edition is basically a slightly restricted version of SQL Server so if you ever decide you need to move to the less restricted version you can without rewriting a lot of code.)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Php 5.38 Connect SQL Server 2008 DennisThen PHP How-To 1 November 1st, 2011 03:50 AM
LINQ or T-SQL? DennisE ASP.NET 4 General Discussion 2 October 29th, 2011 11:36 AM
LINQ to EF and LINQ to SQL sophia BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 19th, 2011 12:16 PM
LINQ to SQL or not? gvdamn BOOK: Professional DotNetNuke Module Programming ISBN: 978-0-470-17116-5 2 August 20th, 2009 05:08 AM
LINQ to SQL bakm04 BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 0 August 17th, 2009 04:07 PM



All times are GMT -4. The time now is 03:38 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.