Problem with Xml schema

I

IR

I have pretty big table - around 100 fields. But I need to load into DataSet
just few of them.
I am trying to use XML schema for this purpose.
XSDSchema1.xsd contains schema for this table with these several fields I
actually need.

I am using the following code to populate dataset:

SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM SomeTable", Cnn);
DataSet ds = new DataSet();
ds.ReadXmlSchema (Server.MapPath(_Server_Root)+ "Test1\\XSDSchema1.xsd");
da.Fill(ds, "SomeTable");
dgr.DataSource = ds.Tables[0]; // dgr - data grid component
if (!IsPostBack) {
dgr.DataBind();
}

The problem is, I am getting ALL fields from "SomeTable" table, instead of
several of them specified in XSDSchema1.xsd.
Specifying these fields in SqlDataAdapter constructor, like this
SqlDataAdapter da = new SqlDataAdapter("SELECT f1, f2, f3, f4, f5 FROM
SomeTable", Cnn);
is not solution - I need to be able control list of displayable fields by
editing XSDSchema1.xsd.
Is there any way to solve this problem?

Your help will be very much appreciated.

Igor
 
G

Guest

Hi
Before you fill the dataset, add the following

dataadapter1.MissingSchemaAction = MissingSchemaAction.Ignore

This will ignore any schema mismatch and load the data.

Thanks
Ibrahim
 
R

Rami Saad

Hello,

You can enforce the constraints of the dataset. That way, as long as there
are no missing constraints, the loaded data will be as in the schema.
You can do that through the following:
ds.EnforceConstraints=true;
Hope this helps solve your problem.

Regards,
Rami Saad
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
P

Paul Clement

¤ I have pretty big table - around 100 fields. But I need to load into DataSet
¤ just few of them.
¤ I am trying to use XML schema for this purpose.
¤ XSDSchema1.xsd contains schema for this table with these several fields I
¤ actually need.
¤
¤ I am using the following code to populate dataset:
¤
¤ SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM SomeTable", Cnn);
¤ DataSet ds = new DataSet();
¤ ds.ReadXmlSchema (Server.MapPath(_Server_Root)+ "Test1\\XSDSchema1.xsd");
¤ da.Fill(ds, "SomeTable");
¤ dgr.DataSource = ds.Tables[0]; // dgr - data grid component
¤ if (!IsPostBack) {
¤ dgr.DataBind();
¤ }
¤
¤ The problem is, I am getting ALL fields from "SomeTable" table, instead of
¤ several of them specified in XSDSchema1.xsd.
¤ Specifying these fields in SqlDataAdapter constructor, like this
¤ SqlDataAdapter da = new SqlDataAdapter("SELECT f1, f2, f3, f4, f5 FROM
¤ SomeTable", Cnn);
¤ is not solution - I need to be able control list of displayable fields by
¤ editing XSDSchema1.xsd.
¤ Is there any way to solve this problem?
¤

If you want to use XML template queries you need to use the SQLXML managed classes instead:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqlxml3/htm/dotnet_3jjn.asp


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
I

IR

dataadapter1.MissingSchemaAction = MissingSchemaAction.Ignore

This did help! Now it works fine!

Thanks a lot to everybody who replied!

Igor
 

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