Opening line for a new class?

  • Thread starter Thread starter Stephen Russell
  • Start date Start date
S

Stephen Russell

In the past public void has worked. But I need to return an XMLDocument,
and this class needs a string param for the SP to call.

public void makeXML (string lcStatement) wont allow me to return a doc. I
guess too many beers last night?

XmlDoc = new XmlDataDocument();

XmlDoc.LoadXml(XmlRdr.ReadOuterXml());

// return the document

return (XmlDoc) ; I bomb here.

TIA

--
Stephen Russell
S.R. & Associates
Memphis TN


901.246-0159
Steve says get rid of the notat_ to send him a reply!
 
Stephen,

Change the void to "XmlDataDocument" and it should work. The reason it
fails is the return type needs to be specified.

Hope this helps.
 
I tried that and I found that my problem is my TRY / CATCH / FAIL.

I'd rather have that in place then comment them out for the class to
compile. Any ideas?

Code here:
public class XMLData

{

public XMLData()

{


}

public XmlDataDocument makeXML (string lcStatement)

{

string strConnection = "SERVER=(local);Trusted_Connection=Yes ";


string strSQL = lcStatement ;

//try

//{

SqlConnection objConnection = new SqlConnection(strConnection);

SqlCommand objCommand = new SqlCommand(strSQL, objConnection);

XmlReader XmlRdr; //= new XmlTextReader();

XmlDataDocument XmlDoc; //= new XmlDataDocument();


objConnection.Open();

// create xml read to acces the xml

XmlRdr = objCommand.ExecuteXmlReader();

//XmlReader = objCommand.ExecuteXmlReader();

// move to the first content node, bypassing any schema, comments, etc.

XmlRdr.MoveToContent();

// populate xml data document

XmlDoc = new XmlDataDocument();

XmlDoc.LoadXml(XmlRdr.ReadOuterXml());

// return the document

return (XmlDoc) ;

//}


// catch


--
Stephen Russell
S.R. & Associates
Memphis TN

901.246-0159
Steve says get rid of the notat_ to send him a reply!

Nicholas Paldino said:
Stephen,

Change the void to "XmlDataDocument" and it should work. The reason it
fails is the return type needs to be specified.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Stephen Russell said:
In the past public void has worked. But I need to return an XMLDocument,
and this class needs a string param for the SP to call.

public void makeXML (string lcStatement) wont allow me to return a doc. I
guess too many beers last night?

XmlDoc = new XmlDataDocument();

XmlDoc.LoadXml(XmlRdr.ReadOuterXml());

// return the document

return (XmlDoc) ; I bomb here.

TIA

--
Stephen Russell
S.R. & Associates
Memphis TN


901.246-0159
Steve says get rid of the notat_ to send him a reply!
 
Stephen Russell said:
I tried that and I found that my problem is my TRY / CATCH / FAIL.

I'd rather have that in place then comment them out for the class to
compile. Any ideas?

To be honest, I'd suggest going back to basics. Forget SQL and XML for
the moment, and just learn the very basics of C# with a tutorial. If
you keep going with your current complex code before getting a thorough
grounding in C#, you're likely to get unstuck quickly.

See http://www.pobox.com/~skeet/java/learning.html for more thoughts
about this (from a Java perspective, but the basis is the same).
 
A basic lack of understanding of C# or for that matter any stongly typed
language.


public void makeXML (string lcStatement) wont allow me to return a
doc. I

The void in the above line tells the compiler that this function does
not return a value.
return (XmlDoc) ; I bomb here.

This line tells the compiler to return a value. It is rightly confused.

public XmlDataDocument makeXML (string lcStatement)

Tells the compiler that you want to return a document. The compiler
should be happy.
 
Again a lack of understanding.
public XmlDataDocument makeXML (string lcStatement)

{

string strConnection = "SERVER=(local);Trusted_Connection=Yes ";
string strSQL = lcStatement ;
try
{
return (XmlDoc) ;
}
catch

Ok what are you going to do here? You have told the compiler that this
function will return a document. Do so.

It might be as simple as to finish off the funtion.
catch
{
XmlDataDocument empty;
return empty;
}
}

the calling function process would look like

XmlDataDocument doc;
doc = makeXML("something here");
if (null == doc)
{
//it didn't work
}
else
{
//it did work
}
 
Back
Top