DataSets designed in wizard

  • Thread starter Thread starter rogersmail
  • Start date Start date
R

rogersmail

Greetings,

I am new to this and have some problems.

I created a dataset using the vs2005 GUI and want to load the dataset
using code in the back end

I have:

XmlDocument xmlDoc = new XmlDocument();

dsSampleTableAdapters.tblSamplesTableAdapter sample = new
dsSampleTableAdapters.tblSamplesTableAdapter();

sample.GetSampleData(sample_id);

//DataSet ds = new DataSet
// dsSample ds = new dsSample
// xmlDoc = ds.GetXml();

Console.WriteLine(xmlDoc);
return xmlDoc;

The problem is that I am not sure where the sample.getSampleData is
acutally storing the data. I tried to set ds = sample.getSampleData
moving the new dataset lines above that obviously.

All I need to do is to retrieve the dataset I created in the gui and
return it as XML to a web service or as a custom object to a thick
client.

Any help is appreicatied.

Thanks
Roger
 
Roger,

A XML document is rarely to process as a XML dataset.

A strongly typed dataset is even more restricted because it is a class
around (inheriting) a dataset.

If I have understood you well, than you can do what you want (assuming that
you have used the 2005 datasource wizard)
\\\
EmployeesTableAdapter.Fill(NorthwindDataSet.Employees)
NorthwindDataSet.WriteXml("C:\test1\test.xml")
///
(The table is translated direct by this to a dataset)

I hope this helps,

Cor
 
Cor,

Thank you for the reply.

I did not create the Fill method as I did not want to fill a complete
database into memory.
Also the Fill and GetData method SQL statements seem to be the same.
I am not wanting to write it to a file.

What I need to do is to get the data from the database hence generating
the get method,
move it into XML and return it to the service layer. The service layer
will determine how to which client to deliver it to. I don't want my
webservice to return the dataset as it is called from various
platforms.

This code
dsSampleTableAdapters.tblSamplesTableAdapter sample = new
dsSampleTableAdapters.tblSamplesTableAdapter();

dsSample.tblSamplesDataTable data =
sample.GetSampleData(sample_id);

seems to load the datatable
but not the dataset

The reason for me using a dataset is that I have multiple databases
with a very complex schema. I figured that the dataset could handle
that better. But I have no idea how to return that as xml


Thanks
Roger
 
Roger,

I don't oversee the problem, however if you have the table and need that
into the dataset than it is simple.

\\\
DatasSt ds = new DataSet();
ds.Tables.Add("Your datatable");
ds.WriteXml("your path");
///

I hope this helps without investigating your problem.

Cor
 
I appreciate your time and patients. But what I need to know is when
you put
DataSet ds = new DataSet();
are you creating another dataset outside of the one you created in the
designer?

Adding tables I understand, but I only want to add one row of a
particular table and multiple rows of other tables. I can do that using
the relationships after I generate the SQL for the DataAdapter.

ds.WriteXml("your path")
Here is where I am having more trouble as I want to generate this in
memory only not to a disk.

Thanks you
Roger
 
Cor,

I really appreciate your help. But I need to bother you again if I
can.

I was thinking about your suggestion to write the XML file to a disk.
Some of the things I am worried about"
1. The file will be over written by another user
2. The resources required by each piece of the application to process
the document (reading and writing to the disk)

Am I worring about nothing?

Thanks
Roger
 
Rogers,

I realized me after sending that you would use it for a webservice.

I had trying something in 2005 a while back the same problem as you packing
it in that dataset as an envelope was than the solution.

ds.tables.add(table)

this create only a kind of wrapper (envelope) around your table.

the ds.writeXml(table) is only a way to test, although this is as well a
method to stream it should not be to disk.

Why don't you try it.

Cor
 
Cor,

Here is the basis of what I was looking for. I am posting this for
others to see.
I used your table add method instead of the connection strings they
give but I still need to touch up the XML as soon as I get it to print
out in my web page.

http://www.15seconds.com/Issue/040708.htm

public XmlDocument GetEmpDetailsByEmpID (int employeeID)
{
string connString =
System.Configuration.ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConnection = new SqlConnection(connString);
try
{
DataSet employeeDataset = new DataSet("EmployeesRoot");
//Pass in the name of the stored procedure to be executed and the
SqlConnection
object as the argument
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand command = new SqlCommand("Select * from Employees Where
EmployeeID ="
+ employeeID.ToString(),sqlConnection);
//Set the SqlCommand object properties
command.CommandType = CommandType.Text;
adapter.SelectCommand = command;
//Fill the Dataset with the return value from the stored procedure
adapter.Fill(employeeDataset,"Employees" );
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(employeeDataset.GetXml());
return xmlDoc;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (sqlConnection.State == ConnectionState.Open)
{
sqlConnection.Close();
}
}

Thank you very much for your help.
 
Roger,

It is nice that you found your solution, however if you pass it as dataset
you get the same result. This is almost standard Net 1.1 what you show. You
asked it for a DataSet designed with the wizard see your subject. Now it is
a little bit misleading for others.

This was enough for 1.1 without a wizard (I don't see what you do with the
exception here by the way, it looks for me as you let it be and than you can
take for the same the Using)
 
The lines I found most useful and should have posted was

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(employeeDataset.GetXml());
return xmlDoc;

The other code was just surrounding these lines. This will give a
dataset version of the XML doc, but I don't think that its possible to
get a standard format such as
<employee>
<first_name>joe</first_name>
<last_name>joe</last_name>
</employee>

I know I mixed employee with sample which was posted originally, but
the idea is there.

I posted a link for that reason that I wanted others to know where I
found it so they can read it too..

My apologies for misleading code.

Thanks
Roger
 
Roger,
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(employeeDataset.GetXml());
return xmlDoc;
Those lines I found as well interesting.

Although I doubt that they are needed. I use a clear dataset without that in
a HTML page which uses this kind of javascript

var MyXML = new ActiveXObject("Msxml2.DOMDocument");
etc etc

However, to be clear, I do not intent that you should think about it to
change it or whatever, if your solution works I would keep it as it is and
works fine.

This is just for the information.

Cor
 
Back
Top