Introduction
Have you ever used a vague combination such as ASP.NET (2.0) and a database like MySQL? In this project, you would get data access functionality for MySQL that would help you to minimize your efforts to write a Data Access Layer in your Web Projects while using such a combination.
Background
The MySql.Data
namespace consists most of the required classes. This namespace have some methods in the classes which do not accommodate all features such as ExecuteDataset
, and some of them, say, MySqlHelper
, do not support Stored Procedures with parameters. In this project, the data access layer would contain methods such as ExecuteDataset
, ExecuteNonQuery
, ExecuteScalar
, and ExecuteReader
, which would use Stored Procedures and queries, both with and without parameters.
Using the code
Here is how to use the data access class in the code. For detailed implementation, please go through the demo project. Set the connection string appropriately in the web.config file.
DataSet dsEmployee = new DataSet();
dsEmployee = DataAccess.ExecuteDataSet(CommandType.StoredProcedure,
"EmployeeDetails");
DataSet dsEmployee = new DataSet();
MySqlParameter[] mySqlParams = new MySqlParameter[1];
mySqlParams[0] = new MySqlParameter();
mySqlParams[0].ParameterName = "?EmpId";
mySqlParams[0].Value = 2;
dsEmployee = DataAccess.ExecuteDataSet(CommandType.StoredProcedure,
"EmployeeDetails",mySqlParams);
DataSet dsEmployee = new DataSet();
MySqlParameter[] mySqlParams = new MySqlParameter[1];
mySqlParams[0] = new MySqlParameter();
mySqlParams[0].ParameterName = "?EmpId";
mySqlParams[0].Value = 2;
dsEmployee = DataAccess.ExecuteDataSet(CommandType.Text,
"Select * from employee where Id =?EmpId", mySqlParams);