Unable to update the EntitySet because it has a DefiningQuery and no element exists in the element to support the current operation

by viral 10. May 2012 06:00

 

Working on Entity framwork sometime like fun and some time it pull your hair out.

Last time I come up with error :

 

Unable to update the EntitySet because it has a DefiningQuery
and no element exists in the element to support the current operation.

 

I have tried and check DefiningQuery but didn't find any problem related to that.

After haveing some deep research I find out I forgot to give Primary Key to table Embarassed.

Entity Framework need to have Primary Key constrain on table.

So it should be first stpe to make sure you have Primary Key on your table.

And if you have any error like this while Entity Framework then first step should be check if you forgoton to add Primary Key in your table.

It can save your much time.Tongue out

1570 views

Tags: ,

ASP.NET | General | Entity Framework

HTTP Error 404.8

by viral 7. May 2012 13:55

Resently I am having problem of 404.8 server error in IIS 7.

The error is :

 

HTTP Error 404.8 - Not Found
The request filtering module is configured to deny a path in the URL that contains a hiddenSegment section.



First I little confuse here as all I have done is giving page from App_Data folder's file.

Somethink like http://www.yourdomain.com/Add_Data/filename.
Yes I know giving direct path is somewhat not good idea but it is more like backend process which user will never going to know.

After having test it with differnt style the error was still there.


After doing deep research I found that it is IIS 7 policy to not able to access hidden folder.
I just come know that App_Data folder is consider as hidden folder in Web Application. So the error occure.
So the quick fix for this type of problem is just change folder of your file and path your code be rock again.Laughing

 

1543 views

Tags: ,

ASP.NET | General

Import Data From Excel Sheet

by viral 20. April 2012 08:03

 

Some times in any application we need to import data from the out source like excel sheet using DOTNET

and this create problem so here I present you the solution.

 

On asp control on button's click event you have to put this code to import data from Exce sheet.

 

 

 

protected void btninsertdata_Click(object sender, EventArgs e)
    {
        OleDbConnection ocon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("example.xls") + ";Extended Properties=Excel 8.0");
        try
        {
            OleDbCommand ocmd = new OleDbCommand("select * from [Sheet1$]", ocon);
            ocon.Open();
            OleDbDataReader ObjOleDr = ocmd.ExecuteReader();
            string fname = "";
            string lname = "";
            string mobnum = "";
            string city = "";
            string state = "";
            string zip = "";
            while (ObjOleDr.Read())
            {
                fname = ValidData(ObjOleDr, 0);
                lname = ValidData(ObjOleDr, 1);
                mobnum = ValidData(ObjOleDr, 2);
                city = ValidData(ObjOleDr, 3);
                state = ValidData(ObjOleDr, 4);
                zip = ValidData(ObjOleDr, 5);
                insertdataintosql(fname, lname, mobnum, city, state, zip);
            }
            ocon.Close();
        }
        catch (DataException ee)
        {
            lblmsg.Text = ee.Message;
            lblmsg.ForeColor = System.Drawing.Color.Red;
        }
        finally
        {
            lblmsg.Text = "Data Inserted Sucessfully";
            lblmsg.ForeColor = System.Drawing.Color.Green;
        }
    }
		
	protected string ValidData(OleDbDataReader myreader, int stval)
    {
        object ObjVal = myreader[stval];
        if (ObjVal != DBNull.Value)
            return ObjVal.ToString();
        else
            return Convert.ToString(0);
    }
	
	public void insertdataintosql(string fname, string lname, string mobnum, string city, string state, string zip)
    {
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Project\Online Examination\Reserch Data\ImportExcel2SQLServer\ImportExcel2SQLServer\ImportExcel2SQLServer\App_Data\exceltosql.mdf;Integrated Security=True;User Instance=True");
        string Query = "insert into emp(fname,lname,mobnum,city,state,zip) values('"+fname+"','"+lname+"','"+mobnum+"','"+city+"','"+state+"','"+zip+"')";
        SqlCommand cmd = new SqlCommand(Query,con);        
        cmd.CommandType = CommandType.Text;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

So , This is the solution.

If you still having problem then Request is I will give you a project which show you same thing.

 

1492 views

Tags: ,

ASP.NET

About Auther

Viral Upadhyay has completed his Engineer Degree in year 2006.

Since he working as ASP.Net Developer.

He also work on Silverlight and other tools like LINQ, JQuery, WCF and different .Net Platform.

Right now He is working as Freelancer.