Object Refrence Error in MySQL + Entity framework

dunerdillon

New Member
I am trying to learn entity framework with MySql database.
Trying to save the data with following code:\[code\]protected void btnSubmit_Click(object sender, EventArgs e){ if (txtName.Text == string.Empty || txtAge.Text == string.Empty) { lblMsg.Text = "Please enter proper details first"; return; } employee emp = new employee(); emp.Name = txtName.Text; emp.Age = Convert.ToInt32(txtAge.Text); using (entityframeworkEntities context = new entityframeworkEntities()) { context.AddToemployees(emp); if (context.SaveChanges() == 1) // Error Part { lblMsg.Text = "Saved Successfully."; } }}\[/code\]The code is getting an \[code\]Object Reference\[/code\] error on \[code\]if (context.SaveChanges() == 1)\[/code\] . Even the \[code\]emp\[/code\] is not added to the \[code\]contaxt\[/code\] object.When I debug the code, the debugger goes to following part:\[code\]public entityframeworkEntities() : base("name=entityframeworkEntities", "entityframeworkEntities") { this.OnContextCreated(); }\[/code\]Even on this part, the debugger comes to the braces but skip \[code\]this.OnContextCreated();\[/code\] line. Here is my connection string in Web.Config\[code\]<add name="entityframeworkEntities" connectionString="metadata=res://*/ApplicationWithMySql.csdl|res://*/ApplicationWithMySql.ssdl|res://*/ApplicationWithMySql.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;User Id=root;password=root;database=entityframework"" providerName="System.Data.EntityClient" />\[/code\]Please help me, where am I going wrong? Thank you!
 
Back
Top