我有一个存储过程,我把它连接到我的项目,我想知道我可以通过不同的参数类型:在C#.NET应用程序传递存储过程的参数
存储过程:
[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”,变量)'让数据库处理SQL数据类型 – MethodMan
@DJKRAZE感谢您的提示,但我实际上担心传递方法中的参数。 – Masriyah