473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Opening line for a new class?

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!
Nov 15 '05 #1
5 1184
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]
- mv*@spam.guard.caspershouse.com

"Stephen Russell" <srussell@notat_lotmate.com> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
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!

Nov 15 '05 #2
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OX**************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Stephen Russell" <srussell@notat_lotmate.com> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
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!


Nov 15 '05 #3
Stephen Russell <srussell@notat_lotmate.com> wrote:
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).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
A basic lack of understanding of C# or for that matter any stongly typed
language.
"Stephen Russell" <srussell@notat_lotmate.com> wrote in
news:Ou**************@TK2MSFTNGP12.phx.gbl:
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.
Nov 15 '05 #5
Again a lack of understanding.

public XmlDataDocument makeXML (string lcStatement)

{

string strConnection = "SERVER=(local);Trusted_Connection=Yes ";
string strSQL = lcStatement ;
try
{ <snip> 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
}

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: PM | last post by:
Has anyone found a way to open a file exclusively where it will fail if the file is already open, i have tried the following _FileStream = new FileStream(@"C:\Data.txt", FileMode.Open,...
1
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket...
11
by: Ahmet AKGUN | last post by:
Hi; is it possible to open one form in .net platform that we have its name in string ? I have string sFormName = "frmCustomer"; and I must automatically open Customer form. or is it...
21
by: Dino M. Buljubasic | last post by:
I'd like my application to be able to detect default email application (MS Outlook or whichever is set to be default) so that the user can enter the email body, address, subject line and send the...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
11
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
2
by: Craig | last post by:
Hi there, I'm trying to open colour BMPs using PIL and I'm getting the following errors. Opening a 16 colour BMP I get: Traceback (most recent call last): File "<pyshell#3>", line 1, in...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
by: bbrewder | last post by:
I am struggling with some MSAccess automation issues. Basically, we have a .Net application that uses MSAccess for reporting (legacy code). We are able to launch MSAccess fine and even work with...
2
by: freddukes | last post by:
Okay... I'm a PHP noob but I have a good background in C++ and Python... Now all I want to do is iterate through the following file, and appending all products to an array, with information stored...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.