Solved

C# Web Application MySQL Data Access

Posted on 2014-04-17
3
577 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now