我是新来的Entity framework
。我只是尝试代码优先模式。我想将数据插入到学生表中。
//this is the insert.cs code
public class Insertingvalue
{
public Insertingvalue()
{
}
public static void addvalue()
{
var newstudent=new Student();
newstudent.student_id= 008;
newstudent.student_name = "lakshmi";
newstudent.class_name = "12th";
newstudent.mark1 = 60;
newstudent.mark2 = 70;
newstudent.mark3 = 80;
using (var dbcon=new Context())
{
//dbcon.Database.Connection.Open();
dbcon.Students.Add(newstudent);
dbcon.SaveChanges();
}
}
}
我的连接字符串如下
<connectionStrings>
<add name="Context"
connectionString="Data Source=AFRESH-PC\SQLEXPRESS;
Initial Catalog=laks;
Integrated Security=True;
App=EntityFramework"
providerName="System.Data.EntityClient"/>
</connectionStrings>
错误是不支持关键字:“数据源”。我无法修复此bug.pls帮助我
由于不正确的providerName属性(将System.Data.EntityClient放置在此处)而引起问题,但如果要连接到Microsoft SQL Server,则应使用System.Data.SqlClient。对于最常见的providerName选项,请参见以下内容:
http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.sqldatasource.providername.aspx
更改此属性后,您的代码应像超级按钮一样工作:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句