vs2005 datasources

T

T. Wong

If I create a datasource after dragging a GridView onto an aspx page it puts
my sql in the .aspx file. SQL in the aspx file is just wrong - it's like
going back to asp where we had code and sql in the asp file.

So I figured out how to create a TableAdapter:Dataset and now I have an .xsd
in my App_code folder. I drag a GridView onto an aspx page and now I want
to connect it to the dataset (so I won't have sql in my aspx file) but I
can't seem to do it.

Is there a way to do it?

Thanks for any help,
T
 
O

Otis Mukinfus

If I create a datasource after dragging a GridView onto an aspx page it puts
my sql in the .aspx file. SQL in the aspx file is just wrong - it's like
going back to asp where we had code and sql in the asp file.

So I figured out how to create a TableAdapter:Dataset and now I have an .xsd
in my App_code folder. I drag a GridView onto an aspx page and now I want
to connect it to the dataset (so I won't have sql in my aspx file) but I
can't seem to do it.

Is there a way to do it?

Thanks for any help,
T

Create a new class in your App_Code folder and use it to create
methods that return DataSets from your DataSet that you created.

In your web pages call that new class to get the DataSets, etc. you
want to bind to.


Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
T

T. Wong

Yes, I know I can do that and it's probably a pretty good practice -
particularly for large complex apps. But.....

VS.NET 2005 has taken away our ability to bind to a dataset at desing time,
no?

It seems to me that TableAdapters:DataSets are the way to go and not this
silly datasource that puts SQL in our pages and can't be shared between
pages.

I'm trying to find the "Best Practice" going forward.
Thanks for your response,
T
 
M

Matthew

No..

Just add a SQLDataSource...
Configure it how you want...

Then to access the info in code:

Dim Dt as Data.DataTable = CType(SqlDataSource1.Select(New
DataSourceSelectArguments), Data.DataView).Table
 
T

T. Wong

But, I don't want to use an asp Datasource because:
1. it can't be shared between pages
2. it puts sql in my aspx file and that's just wrong

I want use a TableAdapter:Dataset that I have put in my App_code folder from
a class in that same folder. I would then call methods in that class from
aspx pages and do a databind to my GridView, or whatever control, in my aspx
codebehind file. That way I can share datasets in my pages and I have no
crapy sql code in my aspx file.

But I can't find a way to reference the TableAdapter:Dataset from my class.

T.
 
O

Otis Mukinfus

But, I don't want to use an asp Datasource because:
1. it can't be shared between pages
2. it puts sql in my aspx file and that's just wrong

I want use a TableAdapter:Dataset that I have put in my App_code folder from
a class in that same folder. I would then call methods in that class from
aspx pages and do a databind to my GridView, or whatever control, in my aspx
codebehind file. That way I can share datasets in my pages and I have no
crapy sql code in my aspx file.

But I can't find a way to reference the TableAdapter:Dataset from my class.
[snip]

I did this just the other day. look in the code generated when to
created you xsd file (YourDataSet.Designer.cs) and search for
TableAdapter you will find a namespace named
YourDataSetTableAdapters. Add a using statement to your class (using
YourDataSetTableAdapters;) and you will be able to call the table
adapters from your code.

Here's an example of code from a test I did for this:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using TestConsole.N5GEDataSetTableAdapters;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
USCitiesTableAdapter ta = new USCitiesTableAdapter();
N5GEDataSet ds = new N5GEDataSet();

ta.Fill(ds.USCities);

DataRow [] cities =
ds.USCities.select("Distinct city = 'arlington'", "City, state
ASC");
}
}
}

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
O

Otis Mukinfus

On Wed, 04 Jan 2006 20:06:37 -0600, Otis Mukinfus

Take DISTINCT out of the sample and it will work....
But, I don't want to use an asp Datasource because:
1. it can't be shared between pages
2. it puts sql in my aspx file and that's just wrong

I want use a TableAdapter:Dataset that I have put in my App_code folder from
a class in that same folder. I would then call methods in that class from
aspx pages and do a databind to my GridView, or whatever control, in my aspx
codebehind file. That way I can share datasets in my pages and I have no
crapy sql code in my aspx file.

But I can't find a way to reference the TableAdapter:Dataset from my class.
[snip]

I did this just the other day. look in the code generated when to
created you xsd file (YourDataSet.Designer.cs) and search for
TableAdapter you will find a namespace named
YourDataSetTableAdapters. Add a using statement to your class (using
YourDataSetTableAdapters;) and you will be able to call the table
adapters from your code.

Here's an example of code from a test I did for this:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using TestConsole.N5GEDataSetTableAdapters;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
USCitiesTableAdapter ta = new USCitiesTableAdapter();
N5GEDataSet ds = new N5GEDataSet();

ta.Fill(ds.USCities);

DataRow [] cities =
ds.USCities.select("Distinct city = 'arlington'", "City, state
ASC");
}
}
}

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
E

ewild

Can you not use an ObjectDataSource?
With you gridview use an objectdatasource rather than a SqlDataSource,
and bind the ObjectDataSource to you DataSet. This will keep your Sql
off the page, and you'l be ale to use you dataset.

Hope this helps

Eric
 
G

Guest

Can you not use an ObjectDataSource?
With you gridview use an ObjectDataSource rather than a SqlDataSource, and
bind the ObjectDataSource to your DataSet. This will keep your Sql off the
page, and you'l be ale to use you dataset.

Hope this helps

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top