Problem with Xml schema

  • Thread starter Thread starter IR
  • Start date Start date
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
 
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
 
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
 
¤ 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)
 
dataadapter1.MissingSchemaAction = MissingSchemaAction.Ignore

This did help! Now it works fine!

Thanks a lot to everybody who replied!

Igor
 
Back
Top