Solved

C# Web Application MySQL Data Access

Posted on 2014-04-17
3
584 Views
Last Modified: 2014-04-18
Hi,

I'm designing a c# class to retrieve data from MySQL in order to provide it to a C# Web Application which will be coded in the future by someone else.  I would like to avoid  passing parameters by reference and/or using out parameters.  My question is what would be the "best" way to structure the class methods?  Some of them will need to return just a success code with a success message.  For these, I'm using something like :

class ReturnValue
{
    int fail;  // will be zero if successful
    string failMessage;   // will be empty if successful
}
ReturnValue returnValue ProcessPayroll(parameter1, parameter2);

Other methods will need to return rows of data along with some sort of success code.  For these I'm using something like:

class GetEmployeesReturnValue
{
    ReturnValue returnValue;
    List<Employee> employees;
}
GetEmployeesReturnValue getEmployeesReturnValue getEmployees(parameter1, parameter2);

So, just about every method will have it's own class which encapsulates it's specific "return value".
Is this something a Web Application developer will be able to easily work with?  Are there better ways for an intermediate C# programmer like myself to implement these data provider methods?

Thank you very much for reading.  And, thank you in advance for whatever advice you might provide.

Curt
0
Comment
Question by:97WideGlide
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Dennis Aries earned 500 total points
ID: 40008374
This is something a webdeveloper can easily work with.

There is no single 'best' solution since a lot of that descision is based on the design of the solution.

I would recommend using an array instead of the List-object. While the List-object is easy to use, that design is not supported in all languages whereas a simple arary is. For your code it will only mean that you use "mylist.ToArray()" to convert your List-object to a static array.

You might also consider using inheritance:
class ReturnValue {
  public bool Status; // true when success, false otherwise
  public string FailureReason;
}


class EmployeeReturnValue: ReturnValue {
// This class will automaticly inherit the properties and functions of the ReturnValue-class
  Employee[] employees;
}

Open in new window


This way, the webdeveloper can use a centralized function that accepts the ReturnValue-class to check the result and pass any of the results he receives.
0
 
LVL 8

Author Comment

by:97WideGlide
ID: 40009513
Great! Thank you very much for your answer.  It helps me alot!  And thank you for pointing out that I can inherit from ReturnValue.
0
 
LVL 8

Author Closing Comment

by:97WideGlide
ID: 40009516
Great! Thank you very much for your answer.  It helps me alot!  And thank you for pointing out that I can inherit from ReturnValue.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read about achieving the basic levels of HRIS security in the workplace.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question