PC Review


Reply
Thread Tools Rate Thread

DefaultDataView does not work?

 
 
Bill Todd
Guest
Posts: n/a
 
      29th Jul 2003
I have a simple Web app using the Northwind database. I have a typed
dataset that contains the Suppliers and Products tables. I need to
sort and filter the Products table. For reasons that are irrelevant to
this problem I cannot use a DataView component.

My WebForm contains the following code, however, after this code
executes the Product records in the DataGrid are not sorted by
ProductName. I have also tried setting the DataView's RowFilter
property and that does not work either. There are no error messages.

private DataView productDataView;
productDataView = northwindDataSet1.Tables["Products"].DefaultView;
productDataView.Sort = "ProductName";
productGrid.DataBind();

The properties of the DataGrid are:

DataSource = northwindDataSet1
DataMember = Products
DataKeyField = ProductId

I have also tried the following version of the code without success.

private DataView productDataView;
productDataView = northwindDataSet1.Tables["Products"].DefaultView;
productDataView.Sort = "ProductName";
productGrid.DataSource = productDataView;
productGrid.DataBind();

What do I have to do to get the DefaultView to work?

Thanks.

--
Bill
 
Reply With Quote
 
 
 
 
vineet batta
Guest
Posts: n/a
 
      30th Jul 2003
I have tested the with following code. it works fine.
Replace server name/Password/Userid of your setup.

private void Page_Load(object sender, System.EventArgs e)
{
DataSet ds = GetDataFromPubs();
DataView dv = ds.Tables
[0].DefaultView ;

dv.Sort = "ProductName";
dgGrid.DataSource = dv;
dgGrid.DataBind();


}

private DataSet GetDataFromPubs()
{
try
{
SqlConnection sqlConn =
new SqlConnection("Initial Catalog=NorthWind;Data Source=
[];User ID=[];Password=[];");

//Open the Connection.
sqlConn.Open();

//TODO: DataReader can be
used for faster access.
DataSet inboundTables =
new DataSet();


string query = "SELECT *
FROM PRODUCTS";


//Create DataAdapter
object and Attach the SqlCommand Object.
SqlDataAdapter sqlData =
new SqlDataAdapter(query,sqlConn);

//Fill the dataset object.
sqlData.Fill
(inboundTables);

sqlConn.Close();

return inboundTables;
}
catch(Exception ex)
{
throw ex;
}
}

Hope it helps.

-Vineet Batta
MCAD
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
difference defaultdataview and a normal dataview? Danny M Microsoft VB .NET 5 1st Aug 2006 12:56 PM
difference defaultdataview and a normal dataview? Danny M Microsoft VB .NET 0 31st Jul 2006 02:44 PM
If I have a work sheet protected and try to run a macro to hide rows or columns it won't work. Correct? Marc Microsoft Excel Programming 2 12th Jul 2006 04:10 AM
Wireless mouse/keyboard don't work after system restart only work after power down tfdempsey@comcast.net Windows XP General 1 1st Apr 2004 04:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 AM.