Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 December 5th, 2006, 04:25 PM
Registered User
 
Join Date: Dec 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default SqlDataAdapter does not have its properties

I tried to use some of the properties of SqlDataAdapter e.g. SelectCommand, Fill, etc. I don't see these properties listed in VS 2005 intellisense.

 
Old December 5th, 2006, 05:22 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

show your code.

Woody Z
http://www.learntoprogramnow.com
 
Old December 5th, 2006, 05:41 PM
Registered User
 
Join Date: Dec 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the code:

SqlConnection MyConnection;
            SqlCommand MyCommand;
            SqlDataAdapter MyAdapter;
            DataTable MyTable = new DataTable();

            MyConnection = new SqlConnection();
            // MyConnection.ConnectionString = "server= E901872; Trusted_Connection= yes; database= AdventureWorks"; //This works too.
            MyConnection.ConnectionString = "Data Source= E901872; Initial Catalog= AdventureWorks; Integrated Security=True";
            // ConfigurationManager.ConnectionStrings["DSN_Northwind"].ConnectionString;

            MyCommand = new SqlCommand();
            MyCommand.CommandText = " SELECT TOP 5 * FROM Person.Contact ";
            MyCommand.CommandType = CommandType.Text;
            MyCommand.Connection = MyConnection;

// MyCommand.Connection.Open(); // Don't have to call this, copied this from Default.aspx.cs
            MyAdapter = new SqlDataAdapter();
            MyAdapter.SelectCommand = MyCommand;
            MyAdapter.Fill(MyTable);

            GridView1.DataSource = MyTable.DefaultView;
            GridView1.DataBind();

            MyAdapter.Dispose();
            MyCommand.Dispose();
            MyConnection.Dispose();

 
Old December 5th, 2006, 05:57 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Everything looks fine regarding the SqlDataAdapter.

I assume you are getting intellisense on the other SqlClient objects such as the SqlCommand?

Does your code run?



Woody Z
http://www.learntoprogramnow.com
 
Old December 5th, 2006, 06:38 PM
Registered User
 
Join Date: Dec 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see other properties and methods of the SqlDataAdapter class as well as all that of the SqlCommand in intellisense.

The code does not compile. It has the following errors:

Error 1 'SqlDataAdapter' does not contain a definition for 'SelectCommand'
Error 2 'SqlDataAdapter' does not contain a definition for 'Fill'

 
Old December 5th, 2006, 07:35 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What other properties and methods are available on the MyAdapter object?

This is not a typical problem. If the other expected methods of the SqlDataAdapter are available, then something odd is going on. What Using statements have you used in the code - could you please show those?

Woody Z
http://www.learntoprogramnow.com
 
Old December 6th, 2006, 11:42 AM
Registered User
 
Join Date: Dec 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I think there's something odd going on. This seems to be not a typical problem. In intellisense, I was able to see all of the properties and methods of the MyAdapter object except for the properties like SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand. When I select to add the references, I see the System.Data.SqlClient.dll having a different version and a different path from the rest of other System namespaces on my pc.

Here's the Using statements I used in the code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.Common;
using System.Data.SqlClient;

Thank you for your responds.

 
Old December 6th, 2006, 12:07 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your using statements all appear to be correct.
Another question:
Are you referencing the System.Data.SqlClient.dll directly? I don't see how you could be doing this without being aware of it.
However, if you are doing this, it is possible that is causing the problem.






Woody Z
http://www.learntoprogramnow.com
 
Old December 6th, 2006, 12:43 PM
Registered User
 
Join Date: Dec 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know what you mean by referencing the System.Data.SqlClient.dll directly.
I just tried to fix the problem by looking at the add references list.

Thanks.

 
Old December 6th, 2006, 12:46 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the solution explorer each project has a References folder - this folder has a list of all the references set for the project. Do you have a listing for System.Data.SqlClient, or just System.Data. You should not have one for System.Data.SqlClient - and this is what I want to check.

Woody Z
http://www.learntoprogramnow.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
sqldataadapter vgsgowrisankar C# 2005 7 April 23rd, 2008 04:32 PM
SqlDataAdapter DanRoche .NET Framework 1.x 3 August 20th, 2007 04:04 AM
SqlDataAdapter does not have its properties listed thaopham215 ADO.NET 0 December 5th, 2006 04:33 PM
SqlDataAdapter Issue Tom Wing VB.NET 2002/2003 Basics 2 February 6th, 2006 01:43 PM
sqlDataAdapter [email protected] ADO.NET 1 April 8th, 2004 12:28 AM





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