Am trying to insert record and this error shows up
Exception Details: System.Data.SqlClient.SqlException: Operand type clash: datetime is incompatible with text
Server Error in '/' Application.
Operand type clash: datetime is incompatible with text
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Operand type clash: datetime is incompatible with text
Source Error:
Line 169: cmd.Parameters.AddWithValue("@Path", "NULL");
Line 170: con.Open();
Line 171: cmd.ExecuteNonQuery();
Line 172: con.Close();
Line 173: }
IINSERT CODE
protected void btnSharenow_Click(object sender, EventArgs e)
{
string modelId = (SharePost.Row.FindControl("lblModalId") as Label).Text;
string userName = (SharePost.Row.FindControl("lblUserName") as Label).Text;
string fuserName = (SharePost.Row.FindControl("lblfUserName") as Label).Text;
string contentPost = (SharePost.Row.FindControl("lblpost") as Label).Text;
string comment = (SharePost.Row.FindControl("txtcommentshare") as TextBox).Text;
string img = (SharePost.Row.FindControl("Image2") as System.Web.UI.WebControls.Image).ImageUrl.Split('/')[(SharePost.Row.FindControl("Image2") as System.Web.UI.WebControls.Image).ImageUrl.Split('/').Length - 1];
string img2 = (SharePost.Row.FindControl("Image1") as System.Web.UI.WebControls.Image).ImageUrl.Split('/')[(SharePost.Row.FindControl("Image1") as System.Web.UI.WebControls.Image).ImageUrl.Split('/').Length - 1];
// string Shareimg = (SharePost.Row.FindControl("shareimg") as System.Web.UI.WebControls.Image).ImageUrl.Split('/')[(SharePost.Row.FindControl("shareimg") as System.Web.UI.WebControls.Image).ImageUrl.Split('/').Length - 1];
string FRIENDeimg = (SharePost.Row.FindControl("friendIMAGE") as System.Web.UI.WebControls.Image).ImageUrl.Split('/')[(SharePost.Row.FindControl("friendIMAGE") as System.Web.UI.WebControls.Image).ImageUrl.Split('/').Length - 1];
string fname = (SharePost.Row.FindControl("lblfname") as Label).Text;
// string friendname = (SharePost.Row.FindControl("lblfriendname") as Label).Text;
//string sharedate = (SharePost.Row.FindControl("LabShareDate") as Label).Text;
string shareContent = (SharePost.Row.FindControl("LabeShareContent") as Label).Text;
DateTime sharedate = DateTime.Now;
DateTime sendDate = DateTime.Now;
InsertDatabase(userName, fuserName, contentPost, sendDate, modelId, comment, img, img2, FRIENDeimg, fname, sharedate, shareContent);
sb.Append(@"<script type='text/javascript'>");
sb.Append("$(function () {");
sb.Append(" $('#myModal9t').modal('hide');});");
sb.Append("</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModelScript", sb.ToString(), false);
}
private void InsertDatabase(string userName, string fuserName, string contentPost, DateTime sendDate, string modelId, string comment, string img, string img2, string FRIENDeimg, string fname, DateTime sharedate, string shareContent)
{
using (SqlConnection con = new SqlConnection(constrr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO USERPost VALUES(@UserName,@FriendUserName,@fName,@ShareContent,@ShareId,@ShareDate,@Comments,@ShareImageName,@ContentPost,@SendDate,@ImageName,@ImageName1,@TotalCount,@Path)", con))
{
// cmd.Parameters.AddWithValue("@ShareId", modelId);
cmd.Parameters.AddWithValue("@UserName", username = this.Page.User.Identity.Name);
cmd.Parameters.AddWithValue("@FriendUserName", userName);
cmd.Parameters.AddWithValue("@fName", fname);
cmd.Parameters.AddWithValue("@ShareContent", shareContent);
cmd.Parameters.AddWithValue("@ShareId", modelId);
cmd.Parameters.AddWithValue("@ShareDate", sharedate);
cmd.Parameters.AddWithValue("@Comments", comment);
cmd.Parameters.AddWithValue("@ShareImageName", FRIENDeimg);
cmd.Parameters.AddWithValue("@ContentPost", "NULL");
cmd.Parameters.AddWithValue("@SendDate", sendDate);
cmd.Parameters.AddWithValue("@ImageName", "NULL");
cmd.Parameters.AddWithValue("@ImageName1", img2);
// cmd.Parameters.AddWithValue("@VideoName", comment);
// cmd.Parameters.AddWithValue("@Path", comment);
cmd.Parameters.AddWithValue("@TotalCount", "NULL");
cmd.Parameters.AddWithValue("@Path", "NULL");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}