本文介绍了如何使用Ado.Net实体框架向数据库添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好... 我想使用jQuery和ado.net实体向数据库添加数据 这是我的Asp代码 < / form> < script src =../ jQuery / jQuery 1.7.1-min.js>< /脚本> < 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%GT;')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(); $ .aj ax({ url:cpu.aspx / cpusave, 类型:POST, dataType:json, contentType:application / json; charset = utf-8, 数据:JSON.stringify({ processorCodeName:processorCodeName, 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 }), }) }); }); < /脚本> < / body> < / html> 这是我的代码Behind c# </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#<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"} 如何解决这个错误 我创建一个类并将其命名为cpuHow can i solve this ErrorI Create a class and named it cpunamespace 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; } }}推荐答案(文件).ready(function(){(document).ready(function () {('#btnSave')。click(function(){ var ProcessorCodeName =('#btnSave').click(function () { var ProcessorCodeName =('#< %= processorCodeName.ClientID%>')。val(); var Socket =('#<%=processorCodeName.ClientID%>').val(); var Socket = 这篇关于如何使用Ado.Net实体框架向数据库添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-30 03:29