I have develop a function in which insert textbox value and grid view value into data base.
Problem is that my web method call but it will add some time value into database and give me the following error. Its work once time other can’t work.
An error occurred while executing the command definition. See the inner exception for details.
function addData() {
debugger;
var Customers = new Array();
var desigantion = $("#TextBox4").val();
$('[id*=GridView1]').find('tr:has(td)').each(function () {
var Customer = {};
Customer.code = $(this).find("td:nth-child(1)").html();
Customer.Product = $(this).find("td:nth-child(2)").html();
Customer.Rate = $(this).find("td:nth-child(3)").html();
Customers.push(Customer);
});
$.ajax({
type: 'POST',
url: "Default3.aspx/SaveGridViewRowData",
data: '{Customers: ' + JSON.stringify(Customers) + ',desigantion:"' + desigantion + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d) {
alert('Data Saved Sucessfully');
return false;
}
}
});
};
My web method
public class Customerdata
{
public string code { get; set; }
public string Product { get; set; }
public string Rate { get; set; }
}
[System.Web.Services.WebMethod]
public static bool SaveGridViewRowData(List<Customerdata> Customers, string desigantion)
{
using (var db = new TestEntities())
db.Test2(
Designation = desigantion,
a
);
//a = Mytest.ToString();
using (var db = new TesEntities())
if (Customers.Count > 0)
{
foreach (Customerdata Customer in Customers)
{
db.TestProcedure(
Customer. code,
Customer. Product,
Customer. Rate
);
}
}
}
}
public partial class Default5 : System.Web.UI.Page
{
private static string Designation;
protected void Page_Load(object sender, EventArgs e)
{
}
After once time run then it give me an error.
An error occurred while executing the command definition. See the inner exception for details.
please help how i solve it