XSD VS.Net

L

Leon Shaw

After configuring a relation data schema (MyDataSet.xsd) in vs.net, what
code do you use to display that data within two dropdownlist controls (
parent/child) in an web application?
 
M

Marc Hoeppner

Hi Leon,

configuring a typed dataset only gets you halfway there (assuming that's
what you are doing with the XSD). What you still need to do by hand is to
write some ADO.NET code to establish the connection with the database and to
actually load stuff in your dataset. For example, you could define a
SqlDataAdapter, specify a SELECT... query and use .Fill with your typed
DataSet as parameter (if you use SQL Server). It may be a little overkill to
define a typed dataset and use a DataAdapter only to fill two dropdownlists.
Take a look at the Data Access Application
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could be as easy as this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may want to use a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo
 
L

Leon Shaw

Ok I have call the adatper.fill and databind command, but is'nt some type of
code such as Me.DataSet1.WriteXmlSchema(Me.Request.ApplicationPath
"DataSet1.xsd" I have to type to get the database schema from the .xsd file
(I have two relate tables in my .xsd file "States" and "School". when you
select a state from the first dropdownlist the second dropdownlist suppose
to populate itself with the correct schools from that state. However, the
first list populate with the states, (I have autopostback set to true, and
the onchange event firing) but after the page postback the state
dropdownlist displays System.Data.RelatedView over and over again. Thanks
for the help!

Marc Hoeppner said:
Hi Leon,

configuring a typed dataset only gets you halfway there (assuming that's
what you are doing with the XSD). What you still need to do by hand is to
write some ADO.NET code to establish the connection with the database and to
actually load stuff in your dataset. For example, you could define a
SqlDataAdapter, specify a SELECT... query and use .Fill with your typed
DataSet as parameter (if you use SQL Server). It may be a little overkill to
define a typed dataset and use a DataAdapter only to fill two dropdownlists.
Take a look at the Data Access Application
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could be as easy as this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may want to use a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


Leon Shaw said:
After configuring a relation data schema (MyDataSet.xsd) in vs.net, what
code do you use to display that data within two dropdownlist controls (
parent/child) in an web application?
 
M

Marc Hoeppner

Well, basically you can have VS.NET do the grunt work for you. If you
right-click on your project file, select add, then add class, select dataset
and use any name you like (dataset1.xsd) is fine. Now use the server
explorer to drag a few tables in the XSD and use the toolbox to add
references and/or new fields as needed. Now, when you do this and compile
your project, VS.NET will use a tool (XGEN.EXE) to generate a C# file for
you that implements a strongly typed dataset. You can use it like any other
dataset but it is also a strongly typed class with all the parameters that
your tables have. You can also manually change the XSD file or use the GUI
to build your XSD from scratch.

But if all you want to do is to fill two DropDownLists I would recommend to
use the Data Access Application Blocks or simple ADO.NET to get a DataTable
for each table separately and attach these to the dropdownlists.

One other thing: you can help the databind process to find the right columns
to display by the user of DataTextField and DataValueField. For example, if
you have a DataTable with 4 columns (Company, Street, Country, CompanyID)
and you want the ddl to display the Company as text and have the CompanyID
as the value you'd do something like this:

MyDropDownList.DataSource = MyDataTable;
MyDropDownList.DataTextField = "Company";
MyDropDownList.DataValueField = "CompanyID";
MyDropDownList.DataBind();

Hope this helps!!

Best regards,

Marc Höppner
NeoGeo

Leon Shaw said:
Ok I have call the adatper.fill and databind command, but is'nt some type of
code such as Me.DataSet1.WriteXmlSchema(Me.Request.ApplicationPath
"DataSet1.xsd" I have to type to get the database schema from the .xsd file
(I have two relate tables in my .xsd file "States" and "School". when you
select a state from the first dropdownlist the second dropdownlist suppose
to populate itself with the correct schools from that state. However, the
first list populate with the states, (I have autopostback set to true, and
the onchange event firing) but after the page postback the state
dropdownlist displays System.Data.RelatedView over and over again. Thanks
for the help!

Marc Hoeppner said:
Hi Leon,

configuring a typed dataset only gets you halfway there (assuming that's
what you are doing with the XSD). What you still need to do by hand is to
write some ADO.NET code to establish the connection with the database
and
to
actually load stuff in your dataset. For example, you could define a
SqlDataAdapter, specify a SELECT... query and use .Fill with your typed
DataSet as parameter (if you use SQL Server). It may be a little
overkill
to
define a typed dataset and use a DataAdapter only to fill two dropdownlists.
Take a look at the Data Access Application
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could be as easy as this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may want to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo
 
L

Leon Shaw

do you have remote desktop. I would like you to see want I'm doing for
yourself. I have did everything you stated, and have reference multiple
books and is yet to solve the problem. I thinking of setting up a parameter
stored procedure to get the state id to binding the right schools for that
state in the dropdownlist. The reason I chose the .xsd relational dataset
route, it easy to define relationships among tables. What do you think?

Marc Hoeppner said:
Well, basically you can have VS.NET do the grunt work for you. If you
right-click on your project file, select add, then add class, select dataset
and use any name you like (dataset1.xsd) is fine. Now use the server
explorer to drag a few tables in the XSD and use the toolbox to add
references and/or new fields as needed. Now, when you do this and compile
your project, VS.NET will use a tool (XGEN.EXE) to generate a C# file for
you that implements a strongly typed dataset. You can use it like any other
dataset but it is also a strongly typed class with all the parameters that
your tables have. You can also manually change the XSD file or use the GUI
to build your XSD from scratch.

But if all you want to do is to fill two DropDownLists I would recommend to
use the Data Access Application Blocks or simple ADO.NET to get a DataTable
for each table separately and attach these to the dropdownlists.

One other thing: you can help the databind process to find the right columns
to display by the user of DataTextField and DataValueField. For example, if
you have a DataTable with 4 columns (Company, Street, Country, CompanyID)
and you want the ddl to display the Company as text and have the CompanyID
as the value you'd do something like this:

MyDropDownList.DataSource = MyDataTable;
MyDropDownList.DataTextField = "Company";
MyDropDownList.DataValueField = "CompanyID";
MyDropDownList.DataBind();

Hope this helps!!

Best regards,

Marc Höppner
NeoGeo

Leon Shaw said:
Ok I have call the adatper.fill and databind command, but is'nt some
type
of
code such as Me.DataSet1.WriteXmlSchema(Me.Request.ApplicationPath
"DataSet1.xsd" I have to type to get the database schema from the .xsd file
(I have two relate tables in my .xsd file "States" and "School". when you
select a state from the first dropdownlist the second dropdownlist suppose
to populate itself with the correct schools from that state. However, the
first list populate with the states, (I have autopostback set to true, and
the onchange event firing) but after the page postback the state
dropdownlist displays System.Data.RelatedView over and over again. Thanks
for the help!

and overkill
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could be as easy as this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may want to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema (MyDataSet.xsd) in vs.net, what
code do you use to display that data within two dropdownlist
controls
 
M

Marc Hoeppner

I am not sure I get what you want to do. Could you elaborate a little?

webform2.aspx is not good going practice at all as I load all customers and
all orders into the typed dataset. I think webform1.aspx is a much, much
better implementation (faster, easier to read, easier to change, faster...).

Leon Shaw said:
how do do that same code but reference the name of the relationship such as
(CustomersOrders) in the DataSet1.xsd file to populate the dropdownlist.

Marc Hoeppner said:
With regards to your application, I still think there is an easier way
to
do
that. I am sure you know that by now, but just to be safe: You need be aware
that typed datasets don't write the code for you to access and retrieve
data. You still need to do all the loading/saving etc. yourself in code.
Also, the databinding process for web controls does not automatically take
care of connected tables inside a dataset (typed or not), you also have to
do this yourself.

The straight-forward approach to solving your problem (using the Northwind
database) is attached to this post on page webform1.aspx. You need to edit
the connection string and the sample is done using SQL Server or MSDE. The
typed dataset version is on page webform2.aspx.

And yes, I have remote desktop, so we can set up a time if you want to and
I'll give it a quick look.


file
for parameters
that the
GUI hand
define
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may
want
to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema (MyDataSet.xsd) in vs.net,
what
code do you use to display that data within two dropdownlist
controls
(
parent/child) in an web application?
 
L

Leon Shaw

So I should set up a store procedure in my MS SQL 2000 database for cities
(@StateID) and get the StateDropDownList.DataValueField and pass that value
(@StateID) to display the correct Schools in the SchoolDropDownlist?
Correct!


Marc Hoeppner said:
I am not sure I get what you want to do. Could you elaborate a little?

webform2.aspx is not good going practice at all as I load all customers and
all orders into the typed dataset. I think webform1.aspx is a much, much
better implementation (faster, easier to read, easier to change, faster...).

Leon Shaw said:
how do do that same code but reference the name of the relationship such as
(CustomersOrders) in the DataSet1.xsd file to populate the dropdownlist.

to
have
to for
that the
.xsd define
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could be as
easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may want
to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema (MyDataSet.xsd) in
vs.net,
what
code do you use to display that data within two dropdownlist
controls
(
parent/child) in an web application?
 
M

Marc Hoeppner

Yes, you can do that!

Leon Shaw said:
So I should set up a store procedure in my MS SQL 2000 database for cities
(@StateID) and get the StateDropDownList.DataValueField and pass that value
(@StateID) to display the correct Schools in the SchoolDropDownlist?
Correct!


Marc Hoeppner said:
I am not sure I get what you want to do. Could you elaborate a little?

webform2.aspx is not good going practice at all as I load all customers and
all orders into the typed dataset. I think webform1.aspx is a much, much
better implementation (faster, easier to read, easier to change, faster...).

such
as way
to automatically
take have to
edit MSDE.
The to
and If
you like
any use
the is'nt
some
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could be as easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may
want
to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema (MyDataSet.xsd) in
vs.net,
what
code do you use to display that data within two dropdownlist
controls
(
parent/child) in an web application?
 
L

Leon Shaw

is that a better way, and more efficient way of doing it? However, Thanks
for all the help!
Marc Hoeppner said:
Yes, you can do that!

Leon Shaw said:
So I should set up a store procedure in my MS SQL 2000 database for cities
(@StateID) and get the StateDropDownList.DataValueField and pass that value
(@StateID) to display the correct Schools in the SchoolDropDownlist?
Correct!


customers
and
need
want
to doing
for schools
for to
add
get
a from
the
set
do
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could be as
easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you may
want
to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema (MyDataSet.xsd) in
vs.net,
what
code do you use to display that data within two dropdownlist
controls
(
parent/child) in an web application?
 
L

Leon Shaw

I GOT IT TO WORK. THANKS SO MUCH, but so What you are saying is that I don't
even have to use a dataset at all. All I really need to do is use
sqlcommands to pull data into my form for easy selection Then use a dataset
to pull all the information from every form field and update the database?
Correct
Marc Hoeppner said:
The method used in webform1.aspx should be a lot better than using typed
datasets in this case. Depending on your scenario you could some caching or
even load all the orders (in this case) in a dataset if all customers get
selected pretty frequently.

If you still shoot for the typed dataset, you can start with the
webform2.aspx sample and go from there. You can change the sample to use
SPROCs instead of inline SQL, but you still will have to do the filtering of
the dataset either in T-SQL or by use of the Select or Filter functions in
DataSet/DataTable manually.
:)

Leon Shaw said:
is that a better way, and more efficient way of doing it? However, Thanks
for all the help!
much,
much
yourself
in up toolbox
to
generate
file
or to
get DataValueField.
For have
the autopostback
set to
do with
the ..Fill
with
be
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could
be
as
easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet( MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead, so you
may
want
to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema (MyDataSet.xsd)
in
vs.net,
what
code do you use to display that data within two
dropdownlist
controls
(
parent/child) in an web application?
 
M

Marc Hoeppner

Great, congrats!!

A dataset is very powerfull on the one hand, but on the other has a lot of
overhead. So you need to use it appropriately. Yes, you don't need a dataset
to fill a dropdownlist, but you also have to count other factors such as
ease of use and amount of code to type. So, I'd use something similar to the
webform1.aspx approach and make sure that the page caching is set to a long
time period if your data does not changes very often. This way you have the
ease of use as in the first sample, but the database code only gets called a
few times a time for example. So, this was selecting data.
Inserting/updating data can be done by a dataset as well, but if you only
update a few items in a form you can as well use an SPROC and send it the
values from your form directly without a dataset. If you have a larger
application and use data over and over again on different pages, it may be a
good idea to build a couple of typed datasets where appropriate and use them
both for selecting and for inserting/updating.

Leon Shaw said:
I GOT IT TO WORK. THANKS SO MUCH, but so What you are saying is that I don't
even have to use a dataset at all. All I really need to do is use
sqlcommands to pull data into my form for easy selection Then use a dataset
to pull all the information from every form field and update the database?
Correct
Marc Hoeppner said:
The method used in webform1.aspx should be a lot better than using typed
datasets in this case. Depending on your scenario you could some caching or
even load all the orders (in this case) in a dataset if all customers get
selected pretty frequently.

If you still shoot for the typed dataset, you can start with the
webform2.aspx sample and go from there. You can change the sample to use
SPROCs instead of inline SQL, but you still will have to do the
filtering
of
the dataset either in T-SQL or by use of the Select or Filter functions in
DataSet/DataTable manually.
:)

yourself you
also You
need
Server
or setting
up do
you for
you. use
the generate
use
it file find
the
need
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it
could
be
as
easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet(
MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some overhead,
so
you
may
want
to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema (MyDataSet.xsd)
in
vs.net,
what
code do you use to display that data within two
dropdownlist
controls
(
parent/child) in an web application?
 
L

Leon Shaw

Thanks So Much! I will surely apply and share the knowledge.
Marc Hoeppner said:
Great, congrats!!

A dataset is very powerfull on the one hand, but on the other has a lot of
overhead. So you need to use it appropriately. Yes, you don't need a dataset
to fill a dropdownlist, but you also have to count other factors such as
ease of use and amount of code to type. So, I'd use something similar to the
webform1.aspx approach and make sure that the page caching is set to a long
time period if your data does not changes very often. This way you have the
ease of use as in the first sample, but the database code only gets called a
few times a time for example. So, this was selecting data.
Inserting/updating data can be done by a dataset as well, but if you only
update a few items in a form you can as well use an SPROC and send it the
values from your form directly without a dataset. If you have a larger
application and use data over and over again on different pages, it may be a
good idea to build a couple of typed datasets where appropriate and use them
both for selecting and for inserting/updating.

Leon Shaw said:
I GOT IT TO WORK. THANKS SO MUCH, but so What you are saying is that I don't
even have to use a dataset at all. All I really need to do is use
sqlcommands to pull data into my form for easy selection Then use a dataset
to pull all the information from every form field and update the database?
Correct
caching
or filtering
functions
in (using
the Server
What
do use ADO.NET
to and
have command,
but postback
the need connection
with may
be
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could
be
as
easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet(
MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some
overhead,
 
M

Marc Hoeppner

Excellent, glad to be of help!

Leon Shaw said:
Thanks So Much! I will surely apply and share the knowledge.
Marc Hoeppner said:
Great, congrats!!

A dataset is very powerfull on the one hand, but on the other has a lot of
overhead. So you need to use it appropriately. Yes, you don't need a dataset
to fill a dropdownlist, but you also have to count other factors such as
ease of use and amount of code to type. So, I'd use something similar to the
webform1.aspx approach and make sure that the page caching is set to a long
time period if your data does not changes very often. This way you have the
ease of use as in the first sample, but the database code only gets
called
a
few times a time for example. So, this was selecting data.
Inserting/updating data can be done by a dataset as well, but if you only
update a few items in a form you can as well use an SPROC and send it the
values from your form directly without a dataset. If you have a larger
application and use data over and over again on different pages, it may
be
a
good idea to build a couple of typed datasets where appropriate and use them
both for selecting and for inserting/updating.

customers
get functions database
for safe:
You access
and not),
you webform1.aspx.
You if
you want
I'm What work
for Now
use
you
do can
use all
the
DropDownLists
I to
find example,
you
only
Blocks(http://msdn.microsoft.com/netframework/downloads/samples/default.aspx
?pull=/library/en-us/dnbda/html/daab-rm.asp), it could
be
as
easy
as
this
(C#):

DataSet MyDs = SqlHelper.ExecuteDataSet(
MyConnectionString,
CommandType.Text, "select name, value from mytable" );

MyDropDownList.DataSource = MyDs.Tables[0];
MyDropDownList.DataTextField = "name";
MyDropDownList.DataValueField = "value";
MyDropDownList.DataBind();

Note that using a dataset always has some
overhead,
so
you
may
want
to
use
a
SqlDataReader for performance.

Best regards,

Marc Hoeppner
NeoGeo


After configuring a relation data schema
(MyDataSet.xsd)
in
vs.net,
what
code do you use to display that data within two
dropdownlist
controls
(
parent/child) in an web application?
 

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

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top