【发布时间】:2015-03-24 10:52:40
【问题描述】:
我使用 SQL Server 2008 和 C# 已经有一段时间了,但一直在为它的 OOP 方面苦苦挣扎。我通常如下写我的Insert 语句。以下摘录是我正在玩的一个 AJAX 网站
SqlCommand scCommand = new SqlCommand("spLocationsCreate", APMConn);
scCommand.CommandType = CommandType.StoredProcedure;
scCommand.Parameters.Add("@LocationCode", SqlDbType.VarChar, 5).Value = txtLocationCode.Text;
scCommand.Parameters.Add("@Location", SqlDbType.NVarChar, 100).Value = txtLocation.Text;
scCommand.Connection.Open();
scCommand.ExecuteNonQuery();
scCommand.Connection.Close();
上面的工作并向数据库添加了一条记录,我想我会开始使用上面的类 - Set 和 Get。写了下面的类
public class clsLocations
{
public clsLocations()
{
//
// TODO: Add constructor logic here
//
}
private string _LocationCode;
private string _Locations;
public string LocationCode
{
get { return _LocationCode; }
set { _LocationCode = value; }
}
public string Locations
{
get { return _Locations; }
set { _Locations = value; }
}
}
我理解上述内容,但在如何将它与存储过程一起使用以及如何调用它方面遇到了困难。我在网上读过很多文章,但很多都是使用直接 SQL 而不是存储过程和参数
任何帮助将不胜感激
【问题讨论】:
标签: c# sql-server-2008 stored-procedures