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