【发布时间】:2014-11-11 05:15:14
【问题描述】:
下面显示的我的代码是作为内联 SQL 语句创建的。这段代码怎么写成存储过程??
代码是:
public Stream SelectEmployeeImageByID(int theID)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString());
string sql = "SELECT Image FROM Employees WHERE EmployeeId = @EmployeeId";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@EmployeeId", theID);
connection.Open();
object theImg = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])theImg);
}
catch
{
return null;
}
finally
{
connection.Close();
}
}
【问题讨论】:
-
做一些研究。检查此 URL:stackoverflow.com/questions/1260952/…。除此之外,还有很多例子,用google吧。
标签: c# asp.net sql-server sql-server-2008