ASP.NET - [OleDbException (0x80004005): IErrorInfo.GetDescription failed with E_FAIL(0x80004005).]

Asked By raj kumar's on 03-Aug-16 04:37 PM
hi 

i have get the error 
as

IErrorInfo.GetDescription failed with E_FAIL(0x80004005).

My Coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Windows;
using System.Windows;
using System.Data.OleDb;

public partial class About : Page
{
    OleDbConnection con; 
    OleDbCommand odc;
    OleDbDataAdapter da;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\FOR AUTOMATED\\AllDetails.accdb");
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        con.Open();
        odc = new OleDbCommand("Select * from ClassDetails where year='" + drpYear.SelectedItem.Text + "' and semester='" + drpSemester.SelectedItem.Text + "' and section='" + drpSection.SelectedItem.Text + "'", con);
        da = new OleDbDataAdapter(odc);
        DataSet ds = new DataSet();
        da.Fill(ds);  //got the error in this line. while i execute the command in access, i execute correctly
        gv1.DataSource = ds;
        gv1.DataBind();
    }
}

Robbe Morris replied to raj kumar's on 03-Aug-16 04:40 PM
I "think" the year column is actually a keyword that is reserved.  You could try

where [year] = blah blah blah

The other important thing to note here is that your code is wide open to SQL Injection attacks.  I realize it is only Microsoft Access but if you put this on a shared drive with multiple users, one of your wise ass users could destroy the contents of your database with little effort.

Also, using page level connected database objects like OleDbConnection is very, very bad practice.  You are opening, using, closing, and destroying your objects properly.