【发布时间】:2013-07-24 04:50:08
【问题描述】:
为什么要在我们的应用程序中使用sql helper 类。sql helper 类和简单类有什么区别。在什么情况下应该使用sql Helper。请定义类的结构。
【问题讨论】:
-
SqlHelper 类只是使数据访问层更加紧凑,并且可在各种应用程序中重用。请通过codeproject.com/Tips/555870/…
为什么要在我们的应用程序中使用sql helper 类。sql helper 类和简单类有什么区别。在什么情况下应该使用sql Helper。请定义类的结构。
【问题讨论】:
SqlHelper 旨在整合在 ADO.NET 应用程序的数据访问层组件中一次又一次编写的平凡、重复的代码,如下所示:
using Microsoft.ApplicationBlocks.Data;
SqlHelper.ExecuteNonQuery(connection,"INSERT_PERSON",
new SqlParameter("@Name",txtName.Text),
new SqlParameter("@Age",txtAge.Text));
而不是这个:
string connectionString = (string)
ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand("INSERT_PERSON",connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Name",SqlDbType.NVarChar,50));
command.Parameters["@Name"].Value = txtName.Text;
command.Parameters.Add(new SqlParameter("@Age",SqlDbType.NVarChar,10));
command.Parameters["@Age"].Value = txtAge.Text;
connection.Open();
command.ExecuteNonQuery();
connection.Close();
它是 Microsoft 应用程序块框架的一部分。
【讨论】: