unassigned local variable

J

Jon Vaughan

I get the error use of unassigned local variable dsDepartments from the
following ;

I'm sure the answer is simple , but i'm swapping over from VB.Net to C# and
im finding a few strange errors

public DataSet GetAllDepartments()

{

KitchenEngine.KitchenEngine2 objWebservice;

DataSet dsDepartments;

try

{

objWebservice = new KitchenEngine.KitchenEngine2();

dsDepartments = objWebservice.GetAllDepartments();

}

catch (System.Web.Services.Protocols.SoapException exp)

{

MessageBox.Show("Can't connect to the server.","Server Connection");

}

// Least specific:

catch (Exception exp2)

{

MessageBox.Show(exp2.Message,"General Error");

}

return dsDepartments;

}
 
P

Paul G. Tobey [eMVP]

The warning is because you can't guarantee that the variable is set to
anything, I think. Try initializing it to null where you declare it and see
if that fixes the problem.

Paul T.
 

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