Solved

C# Web Application MySQL Data Access

Posted on 2014-04-17
3
583 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

808 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