Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2006, 06:22 AM
Registered User
 
Join Date: Feb 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Switching TableAdapters

Hi, I was wondering if you could help.

I have a DataSet with two seperate TableAdapters, I can connect to either of them perfectly well. This is how I connect to the first one:

Dim dbAdapter As New DepartmentObjectTableAdapters.DepartmentArticlesTa bleAdapter
Dim dbRecordSet As DepartmentObject.DepartmentArticlesDataTable
dbRecordSet = dbAdapter.GetArticles(strViewArchive))

What I would like to do is connect to a different TableAdapter after say, a PostBack... but I get errors saying 'dbAdapter and dbRecordSet are not declared'. This is how I have unsuccessfully tried to do it:


If Page.IsPostBack Then
     Dim dbAdapter As New DepartmentObjectTableAdapters.DepartmentArticlesTa bleAdapter
     Dim dbRecordSet As DepartmentObject.DepartmentArticlesDataTable
Else
     Dim dbAdapter As New DepartmentObjectTableAdapters.DepartmentArticlesArchiveTableAdapter
     Dim dbRecordSet As DepartmentObject.DepartmentArticlesArchiveDataTable
End If
dbRecordSet = dbAdapter.GetArticles(strViewArchive))

Thanks in advance, any help would be appreciated.
 
Old March 28th, 2006, 02:10 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I don't see why that wouldn't work. Trace through the code and see if you can find at what point you get the error

 
Old March 29th, 2006, 06:25 AM
Registered User
 
Join Date: Feb 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.

I think the cause of the problem is that dbAdapter and dbRecordSet are Dim'd inside of the If statement... and at runtime .Net compiles the page but cannot cannot see that they have been set when it gets to dbRecordSet = dbAdapter.GetArticles(strViewArchive)).

Can I Dim them first (outside of an If statement) and then use an If statement to set where they actually point?
 
Old March 29th, 2006, 11:11 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

The fact that you dim them inside of the IF does not matter. I have tried your code on a test page and it works fine. You can try dimming them ouside, although it should not matter.






Similar Threads
Thread Thread Starter Forum Replies Last Post
TableAdapters in Visual Studio 2005 lisabb ASP.NET 2.0 Basics 0 July 18th, 2007 11:44 AM
Switching list content dynamically ... asearle XSLT 1 September 24th, 2006 11:41 AM
Problems with printer switching Sara Access VBA 0 December 20th, 2004 07:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.