【发布时间】:2013-06-03 19:56:09
【问题描述】:
我有一个存储过程,我将它连接到我的项目,我想知道如何传递不同的参数类型:
存储过程:
[dbo].[UploadAssignment]
@studentId int
, @guid uniqueidentifier
, @originalfilename nvarchar(500)
, @uploaddate datetime
在我的项目中:
public virtual IEnumerable<T> GetUploadStudentSubmission<T>(int studentId, .."How should i format the remaining parameters")
{
SqlCommand _command = new SqlCommand("dbo.UploadAssignment");
_command.CommandType = CommandType.StoredProcedure;
_command.Parameters.Add(new SqlParameter { ParameterName = "studentId",SqlDbType = SqlDbType.Int, Value = sectionId});
_command.Parameters.Add(new SqlParameter { ParameterName = "guid", SqlDbType = SqlDbType.Int, Value = guid });
_command.Parameters.Add(new SqlParameter { ParameterName = "originalfilename", SqlDbType = SqlDbType.Int, Value = originalfilename });
_command.Parameters.Add(new SqlParameter { ParameterName = "uploaddate", SqlDbType = SqlDbType.Int, Value = uploaddate });
}
【问题讨论】:
-
我建议将您的
_command.Parameters.Add更改为_command.Parameters.AddWithValue("@paramname", variable)让数据库处理 Sql DataType -
@DJKRAZE 感谢您的提示,但我实际上担心在方法中传递参数。
标签: c# asp.net-mvc stored-procedures