My insert is inserting data very well but the issue is that after inserting there is jquery pop error message saying null, when i click on the ok button it shows anothere error. Meanwhile the data inserted very well into table.
//insert Modal details
$("#btnInsertR").on("click", function () {
if ($(this).val().toLowerCase() == 'save') {
$("#lblText").html('Record saved successfully.');
}
$('#dialog').fadeIn('slow').delay(1000).fadeOut('slow');
});
var id = $('.id').html().trim();
var fname = $('.fname').html().trim();
var senddate = $('.senddate').html().trim();
var username = $('.username').html().trim();
var fusername = $('.fusername').html().trim();
var scontent = $('.scontent').html().trim();
var spostDate = $('.spostDate').html().trim();
var simagename = $('.simagename').html().trim();
var spath = $('.spath').html().trim();
// If you ant to insert "PROFILEPHOTOS/Test.jpg" format then use the below line
var fimagename = $('.fimagename').attr('src').slice(($('.fimagename').attr('src').lastIndexOf('/') + 1), $('.fimagename').attr('src').length);
// var imagename1 = $('.imagename1').attr('src').slice(($('.imagename1').attr('src').lastIndexOf('/') + 1), $('.imagename1').attr('src').length);
//If you ant to insert "Test.jpg" format then use the below line
var comments = $("#cshare").val();
$.ajax({
type: "POST",
url: "Timeline.aspx/GetInsertReShare",
data: '{id:"' + id + '",fname:"' + fname + '",senddate:"' + senddate + '",username:"' + username + '",fusername:"' + fusername + '",scontent:"' + scontent + '",comments:"' + comments + '",spostDate:"' + spostDate + '",simagename:"' + simagename + '",spath:"' + spath + '",fimagename:"' + fimagename + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
$('#myModalreshare2').modal('hide');
// clear value
$(".id").html('');
$(".fimagename").attr('src', '');
$(".senddate").html('');
$(".username").html('');
$(".fusername").html('');
$(".fname").html('');
$(".spostDate").html('');
$(".scontent").html('');
$(".simagename").html('');
$(".spath").html('');
},
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
return false;
});
</script>
-------------------------
public static string GetInsertR(int id, string fname, string fusername, string scontent, string spostDate, string comments, string fimagename, string simagename, string senddate, string spath)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO [SHPOSTS](UserName,FUserName,fName,SContent,ID,SPostDate,Comments,FImageName,SImageName,TotalCount,SPath) VALUES(@UserName,@FUserName,@fName,@SContent,@ID,@SPostDate,@Comments,@FImageName,@SImageName,@TotalCount,@SPath)"))
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
// cmd.Parameters.AddWithValue("@ID", id);
cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.Session["userName"].ToString());
cmd.Parameters.AddWithValue("@FUserName", fusername);
cmd.Parameters.AddWithValue("@fName", fname);
cmd.Parameters.AddWithValue("@SContent", scontent);
cmd.Parameters.AddWithValue("@SPostDate", spostDate);
cmd.Parameters.AddWithValue("@ID", id);
cmd.Parameters.AddWithValue("@Comments", comments);
cmd.Parameters.AddWithValue("@FImageName", fimagename);
cmd.Parameters.AddWithValue("@SImageName", simagename);
cmd.Parameters.AddWithValue("@TotalCount", 1);
cmd.Parameters.AddWithValue("@SPath", spath);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
return "Submited";
}