Scott Mitchell的教程使用Access数据库遇到的问题(一)

问题一:当带有参数查询时,例如:select * from user where userID=@userID出错;
解决方案:
如果正在使用 Access 版的 Northwind,则请使用问号替换 @City 参数。 (SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE City = ?)

问题二:当使用带有子查询的SQL语句时,出错;
解决方案:
Yeah, the typed dataset wizard tends to screw up things a bit.  You end up finding workarounds.  In the case of these subqueries.. I don't know that I would agree, joins are much more efficient if simply because you save all the typing from all those other fields.  I would suggest this to you.  When you are creating a new table wizard, go ahead and do a simple query with all your normal fields (no joins or subqueries), this will allow your tableadapter to successfully auto generate the CRUD stuff (Create, Retrieve, Update, Delete). 

Once you have done that, you will see your datatable and tableadapter view with everything there except your join fields.  Click on your table adapter and you will see that its default query is the getdata query, in the properties window you get insert, update, delete, and select statements.  Go in at this point and change the select statement to reflect the join statements and all the extra fields you want to have.  The tricky part comes when it asks you if you want to refresh your queries.  The wizard basically is asking if you want to refresh your tableadapter and datatable with your newly minted select statement with the joins in there, say NO as this will, in effect, delete your auto generated updates/inserts/deletes.

MSN me if you have any issues with this stuff, I have actually taken Scott's class at the UCSD Extension and spent some time learning from him in a one on one scenario (he is expensive but absolulely worth it if you live in San Diego.

posted @ 2007-11-20 14:19  Fernando  阅读(529)  评论(0编辑  收藏  举报