Vinoth Kumar

Vinoth Kumar

  • 1.3k
  • 450
  • 32.4k

data base store

Jul 10 2017 6:22 AM
public static string SaveData(inputData jsonData)
{
SqlCommand SqlCmd;
SqlConnection SqlCon;
SqlCon = new SqlConnection(@"server=USER1; database=sales; integrated security= true");
SqlCon.Open();
for (int i = 0; i < jsonData.Rows; i++)
{
SqlCmd = new SqlCommand("insert into sales_entry_new(srl_no,sls_man,barcode,p_name,rate,mtr,qty,amount,pdis,pdis_amount,less,tax,cgst,sgst,dic,net_amount,design)values(@srl_no,@sls_man,@barcode,@p_name,@rate,@mtr,@qty,@amount,@pdis,@pdis_amount,@less,@tax,@cgst,@sgst,@dic,@net_amount,@design)", SqlCon);
SqlCmd.Parameters.Add("@srl_no,", SqlDbType.VarChar).Value = jsonData.UserProfiles[i].srl_no;
SqlCmd.Parameters.Add("@sls_man,", SqlDbType.VarChar).Value = jsonData.UserProfiles[i].sls_man;
SqlCmd.Parameters.Add("@barcode,", SqlDbType.VarChar).Value = jsonData.UserProfiles[i].barcode;
SqlCmd.Parameters.Add("@design",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].design;
SqlCmd.Parameters.Add("@p_name", SqlDbType.VarChar).Value = jsonData.UserProfiles[i].p_name;
SqlCmd.Parameters.Add("@rate",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].rate;
SqlCmd.Parameters.Add("@mtr",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].mtr;
SqlCmd.Parameters.Add("@qty",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].qty;
SqlCmd.Parameters.Add("@amount",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].amount;
SqlCmd.Parameters.Add("@pdis",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].pdis;
SqlCmd.Parameters.Add("@pdis_amount",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].pdis_amount;
SqlCmd.Parameters.Add("@less",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].less;
SqlCmd.Parameters.Add("@tax",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].tax;
SqlCmd.Parameters.Add("@cgst",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].cgst;
SqlCmd.Parameters.Add("@sgst",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].sgst;
SqlCmd.Parameters.Add("@dic",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].dic;
SqlCmd.Parameters.Add("@net_amount",SqlDbType.VarChar).Value = jsonData.UserProfiles[i].net_amount;
SqlCmd.ExecuteNonQuery();
}
SqlCon.Close();
return "completed";
}
public class inputData
{
public int Rows;
public List<UserProfile> UserProfiles;
}
public class UserProfile
{
public string srl_no { get; set; }
public string sls_man { get; set; }
public string design { get; set; }
public string barcode { get; set; }
public string p_name { get; set; }
public string rate { get; set; }
public string mtr { get; set; }
public string qty { get; set; }
public string amount { get; set; }
public string pdis { get; set; }
public string pdis_amount { get; set; }
public string less { get; set; }
public string tax { get; set; }
public string cgst { get; set; }
public string sgst { get; set; }
public string dic { get; set; }
public string net_amount { get; set; }
}
 
$(function () {
$("#btnSave").click(function () {
var jData = PrepareInputData();
$.ajax({
type: "POST",
url: "slsentry.aspx/SaveData",
data: "{jsonData:" + jData + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: Success,
error: Error
});
});
function Success(data) { alert(data.d); }
function Error() { }
function PrepareInputData() {
var objData = {};
UserProfiles = [];
var n = 0;
$("#addrow tr:not(:first-child)").each(function () {
var UserProfile = {};
$(this).find("td input").each(function () {
UserProfile[$(this).attr("name")] = $(this).val();
});
n = n + 1;
UserProfiles.push(UserProfile);
});
objData["Rows"] = n;
objData.UserProfiles = UserProfiles;
return JSON.stringify(objData);
}
});
 
what is the error is occured  
 
 

Answers (1)