I have following function:
public Exception createTopic(Topic t)
{
query = "insert into [DisData].[dbo].[discussions]([title],[description],[usrid],[dateadded],[desid],[likes],[shares],[visit],[replyto],[sno]) values(@title,@des,@uid,@dateadded,@did,@like,@share,@visit,@replyto,@sno)";
try
{
com = new SqlCommand(query, con);
com.Parameters.AddWithValue("@title", t.getTitle());
com.Parameters.AddWithValue("@des", t.getDescription());
com.Parameters.AddWithValue("@uid", t.getUsrID());
com.Parameters.AddWithValue("@dateadded", t.getDate());
com.Parameters.AddWithValue("@did", t.getDesID());
com.Parameters.AddWithValue("@like", 0);
com.Parameters.AddWithValue("@share", 0);
com.Parameters.AddWithValue("@visit", 0);
com.Parameters.AddWithValue("@replyto", t.getReplyToID());
com.Parameters.AddWithValue("@sno", getDisCount() + 1);
con.Open();
com.ExecuteNonQuery();
con.Close();
res.Redirect("viewthread.aspx?id=" + t.getDesID());
return null;
}
catch (Exception e)
{
con.Close(); return e;
}
}
The connection string is defined in the constructor of containing class. The problem is that, whenever I try to execute this function, it executes without giving any exception, even not on Visual Studio Debugger Console, and also does not updates the database with new entry provided by the user. When I checked for return value of ExecuteNonQuery() it is returning -1. To me the code seem to be okay or may be I am missing something. Please help me to identify it.
I also tried to execute the query by removing all AddWithValue() statements and making the query pre-defined as
insert into [DisData].[dbo].discussions values('Test','TestDes','TestUID','12-12-2012','sdsd',1,1,1,'sdsd',2)
But problem remains the same...