Creating dataset.xsd file programmatically as dragging table from Server explorer fails

C

Chukkalove

Visual studio 2003, MySQL database, MySQL odbc 3.51 driver

Is it possible to create the file dataset.xsd programmatically?

I'm trying to create my dataset1.xsd file for using with crystal reports.
The database is mySQL and the data connection is sat in my server exporer
bar. The tables and fields are enumerated correctly in the server explorer,
but when i try to drag and drop any item onto the dataset1.xsd designer
surface I receive a sql error -

"The wizard detected the following problems when configuring the data
adapter for "users".
Details:
Error in SELECT clause: exression near ""
Error in FROM clause: near ""
Unable to parse query text."

If I press OK, then i receive the message -

"The following unexpected error has occurred:
There were errors dropping "users" onto the designer. The XML schema could
not be interpreted from this object. "

Im stuck and relatively inexperienced so I don't know where to go from here.
I thought that it might be possible to create a dataset from code then write
it to file. How would I go about this please?
 
C

Chukkalove

Chukkalove said:
"The wizard detected the following problems when configuring the data
adapter for "users".
Details:
Error in SELECT clause: exression near ""
Error in FROM clause: near ""
Unable to parse query text."

If I press OK, then i receive the message -

"The following unexpected error has occurred:
There were errors dropping "users" onto the designer. The XML schema could
not be interpreted from this object. "

Ive managed to do it. Thank you anyway.

In case anyone else has the same problem as myself, Ive replied with my own
solution. I remain unable to use the visual studio designer but at least i
dont have to do too much manual work.

Firstly I found and copied the file xsd.exe to my project output directory
then I created the following functions

public class MySqlDataObject:BaseDatabaseObject
{
protected override IDbConnection GetConnection()
{
string ConnectionString = string.Format(
"Server={0};Database={1};Uid={2};Pwd={3};Port={4}",IPAddress,DatabaseName,
SiteID, Password, Port);
return new MySqlConnection(ConnectionString);
}
protected override IDbDataAdapter GetDataAdapter()
{
return new MySqlDataAdapter();
}
}// class

public abstract class BaseDatabaseObject
{
protected abstract IDbConnection GetConnection();
protected abstract IDbDataAdapter GetDataAdapter()

public void CreateDatasetXsd(string sql, string xmlname)
{
IDbConnection Connection = GetConnection();
DataSet ds = new DataSet(xmlname);
IDbDataAdapter Adapter = GetDataAdapter();
Adapter.SelectCommand = Command(sql, Connection);
Adapter.Fill(ds);
// Write schema to xml file
ds.WriteXmlSchema(xmlname + ".xml");
// convert xml to xsd file openable in visual studio
Process.Start("xsd.exe",xmlname + ".xml");
}
}// class

// In main form
BaseDatabaseObject myDatabase = new MySqlDataObject();
myDatabase.CreateDatasetXsd("Select * from Users","users" );
 

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