When I want to add a comment to my database I get the following error(The order is the same as in the database) :
System.Data.SqlClient.SqlException was unhandled by user code
Class=16
ErrorCode=-2146232060
HResult=-2146232060
LineNumber=0
Message=The parameterized query '(@UserId nvarchar(36),@TimeStamp datetime,@CategoryId int,@PostI' expects the parameter '@Comment', which was not supplied.
Number=8178
Procedure=""
Server=MAXIM-HP\DATAMANAGEMENT
Source=.Net SqlClient Data Provider
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at BlogMaxim.Repositories.CommentRepository.Add(Comments comment) in C:\nmct\2e Jaar\1e sem\project\BlogMaxim\BlogMaxim\Repositories\CommentRepository.cs:line 98
at BlogMaxim.Controllers.CommentController.AddComment(Comments comment) in C:\nmct\2e Jaar\1e sem\project\BlogMaxim\BlogMaxim\Controllers\CommentController.cs:line 43
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
InnerException:
This is my method where I add the items into the database.
This is were I make the Comments object:
namespace BlogMaxim.Models {
public class Comments
{
public int Id { get; set; }
public int CategoryId { get; set; }
public int PostId { get; set; }
public string Comment { get; set; }
public string UserId { get; set; }
public DateTime Timestamp { get; set; }
} }
This is my form:
@model IEnumerable<BlogMaxim.Models.Comments>
@if (User.Identity.IsAuthenticated)
{
<form method="post" action="/comment/addcomment">
<label>Vul hier commentaar in: </label>
<input type="hidden" width="150" name="PostId" value="@ViewBag.pId" />
<input type="text" width="150" name="Comment" />
<input type="submit" width="150" value="Toevoegen" />
</form>