Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there ...
I want to add data to DB using jQuery and ado.net Entity
Here is my Asp codes



<asp:Label ID="Label1" runat="server" Text="Processor Code Name">
<asp:TextBox ID="processorCodeName" runat="server" >
<asp:Label ID="Label2" runat="server" Text="Socket">
<asp:TextBox ID="socket" runat="server" >
<asp:Label ID="Label3" runat="server" Text="Number of Cores">
<asp:TextBox ID="numberOfCores" runat="server" >
<asp:Label ID="Label4" runat="server" Text="Core Speed">
<asp:TextBox ID="coreSpeed" runat="server" >
<asp:Label ID="Label5" runat="server" Text="On Die L1 Cache">
<asp:TextBox ID="onDieL1Cache" runat="server" >
<asp:Label ID="Label6" runat="server" Text="On Die L2 Cache">
<asp:TextBox ID="onDieL2Cache" runat="server" >
<asp:Label ID="Label7" runat="server" Text="On Die L3 Cache">
<asp:TextBox ID="onDieL3Cache" runat="server" >
<asp:Label ID="Label8" runat="server" Text="Cmos">
<asp:TextBox ID="cmos" runat="server" >
<asp:Label ID="Label9" runat="server" Text="QPI-GT/s - FSB-MHz Speed">
<asp:TextBox ID="qPIGTsFSBMHzSpeed" runat="server" >
<asp:Label ID="Label10" runat="server" Text="Intagrated Graphic">
<asp:TextBox ID="intagratedGraphic" runat="server" >
<asp:Label ID="Label11" runat="server" Text="Graphic Base Frequency">
<asp:TextBox ID="graphicBaseFrequency" runat="server" >

<asp:Label ID="Label12" runat="server" Text="تصویر1">
<asp:FileUpload ID="Pic1" runat="server" />
<asp:Label ID="Label13" runat="server" Text="تصویر2"> <asp:FileUpload ID="Pic2" runat="server" />
<asp:Label ID="Label14" runat="server" Text="تصویر3"> <asp:FileUpload ID="Pic3" runat="server" />
<asp:Label ID="Label15" runat="server" Text="لوگوی محصول"> <asp:FileUpload ID="Logo" runat="server" />

<asp:Button ID="btnSave" runat="server" Text="ثبت" Width="100px" />




</form>
<script src="../jQuery/jQuery 1.7.1-min.js"></script>
<script>
$(document).ready(function () {
$('#btnSave').click(function () {
var ProcessorCodeName = $('#<%=processorCodeName.ClientID%>').val();
var Socket = $('#<%=socket.ClientID%>').val();
var NumberOfCores = $('#<%=numberOfCores.ClientID%>').val();
var CoreSpeed = $('#<%=coreSpeed.ClientID%>').val();
var OnDieL1Cache = $('#<%=onDieL1Cache.ClientID%>').val();
var OnDieL2Cache = $('#<%=onDieL2Cache.ClientID%>').val();
var OnDieL3Cache = $('#<%=onDieL3Cache.ClientID%>').val();
var Cmos = $('#<%=cmos.ClientID%>').val();
var QPIGTsFSBMHzSpeed = $('#<%=qPIGTsFSBMHzSpeed.ClientID%>').val();
var IntagratedGraphic = $('#<%=intagratedGraphic.ClientID%>').val();
var GraphicBaseFrequency = $('#<%=graphicBaseFrequency.ClientID%>').val();
var pic1 = $('#<%=Pic1.ClientID%>').val();
var pic2 = $('#<%=Pic2.ClientID%>').val();
var pic3 = $('#<%=Pic3.ClientID%>').val();
var logo = $('#<%=Logo.ClientID%>').val();

$.ajax({
url: "cpu.aspx/cpusave",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
"processorCodeName": processorCodeName,
"socket": Socket,
"numberOfCores": numberOfCores,
"coreSpeed": coreSpeed,
"onDieL1Cache": onDieL1Cache,
"onDieL2Cache": onDieL2Cache,
"onDieL3Cache": onDieL3Cache,
"cmos": cmos,
"qPIGTsFSBMHzSpeed": qPIGTsFSBMHzSpeed,
"intagratedGraphic": intagratedGraphic,
"graphicBaseFrequency": iraphicBaseFrequency,
"Pic1": Pic1,
"Pic2": Pic2,
"Pic3": Pic3,
"Logo": Logo
}),
})
});
});
</script>
</body>
</html>

And this is my code Behind c#
C#
<pre lang="cs">[WebMethod]
public string cpusave(string processorCodeName, string socket, string numberOfCore, string coreSpeed, string onDieL1Cache, string onDieL2Cache, string onDieL3Cache,string cmos, string qPIGTsFSBMHzSpeed, string intagratedGraphic, string graphicBaseFrequency, string Pic1,string Pic2,string Pic3,string Logo,string Owner)
{
      string status = "سخت افزار مورد نظر با موفقیت ثبت شد";
     var ab = new cpu1 {ProcessorCodeName = processorCodeName,Socket=socket,NumberOfCore=numberOfCore,CoreSpeed=coreSpeed,OnDieL1Cache=onDieL1Cache,OnDieL2Cache=onDieL2Cache,OnDieL3Cache=onDieL3Cache,Coms=cmos,QPIGTsFSBMHzSpeed=qPIGTsFSBMHzSpeed,IntagratedGraphic=intagratedGraphic,GraphicBaseFrequency=graphicBaseFrequency,pic1=Pic1,pic2=Pic2,pic3=Pic3,logo=Logo,owner=Owner};
     var dc = new arsEntities1();
     dc.cpus.Add(ab); //ERROR here
     dc.SaveChanges();
     status="success"
}

How can i solve this Error
I Create a class and named it cpu
C#
namespace ASPJquerySaveData
{
    public partial class cpu1
    {
        public string CoreSpeed { get; set; }
        public string id { get; set; }
        public string brand { get; set; }
        public string cost { get; set; }
        public string partnercost { get; set; }
        public string ProcessorCodeName { get; set; }
        public string Socket { get; set; }
        public string NumberOfCore { get; set; }
        public string OnDieL1Cache { get; set; }
        public string OnDieL2Cache { get; set; }
        public string OnDieL3Cache { get; set; }
        public string Coms { get; set; }
        public string QPIGTsFSBMHzSpeed { get; set; }
        public string IntagratedGraphic { get; set; }
        public string GraphicBaseFrequency { get; set; }
        public string pic1 { get; set; }
        public string pic2 { get; set; }
        public string pic3 { get; set; }
        public string logo { get; set; }
        public string owner { get; set; }
    }
}
Posted
Updated 31-Jul-14 2:36am
v2
Comments
ZurdoDev 31-Jul-14 8:54am    
Where are you stuck? Have you gone through any tutorials or read any books on this?
m-e-h-d-h-i 31-Jul-14 8:56am    
dc.cpus.Add(ab); //ERROR here
m-e-h-d-h-i 31-Jul-14 9:03am    
the best overloaded method match for system data entity DBset <cpu> has some invalid arguments
Nathan Minier 31-Jul-14 9:25am    
It sounds like your EF ORM didn't map properly in the first place. I'm not familiar with Web Forms implementations, but you should make sure that the arsEntities1 class is setup correctly.

1 solution

Hello ,
Try using entities.AddObject instead of entities.Add in your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900