Solved

C# Web Application MySQL Data Access

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cassandra Select Query 1 57
Word Directory is not in the drop down list 4 26
Data is not showing from images 15 38
Export import database 4 45
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

863 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

24 Experts available now in Live!

Get 1:1 Help Now