Showing posts with label MS Access. Show all posts
Showing posts with label MS Access. Show all posts

Tuesday, May 4, 2010

80040E14 - MS Access Syntax Error message




Please visit my new Web Site https://coderstechzone.com



You may face the "Error: 80040E14 - MS Access Syntax Error message" when you want to execute or run an Insert, Update, Delete or even Select statement. There were several types of error you may encounter like below:

1. Syntax error in FROM clause
2. Syntax error in INSERT INTO statement
3. Syntax error in UPDATE statement
4. Syntax error (missing operator) - caused by ' mark
5. Syntax error (missing operator) - incorrect delimiters
6. Syntax error - division by zero error
7. Mismatched CommandTypeEnum value

The above error may comes for below reasons:
1. Using a Reserved Word for a field name or for a table name.
2. Spaces between field name or table name
3. Attempting to insert single quote within a string/text value
4. Incorrect syntax or typing mistake


Resolution:

Using a Reserved Word for a field name or for a table name:
If you are using any reserve word of MS-Access as a field name or table name then you encounter the error. The simple solution is wrap up the field name or table name by third bracket like:
Select [name], [password], [email] From [Agents]


Spaces between field name or table name:
If you are using any spaces within a field name or table name then you encounter the error. The simple solution is wrap up the field name or table name by third bracket like:
Select [name], [password], [email address] From [Agents]


Attempting to insert single quote within a string/text value:
If you want to insert a text or string value which contains single quotation like 'What's in your mind?' within the value then you encounter an error. Because the single quote telling MS-Access that the string value has ended, and anything afterwards should be treated as legitimate SQL. The simple solution is use string.Replace() method to double any single quotes will resolve your problem. Paramterised queries also the best solution in this regard.

Incorrect syntax or typing mistake:
Try to learn MS-ACCESS SQL syntax will resolve your problem.

Wednesday, November 25, 2009

Bind GridView with MS Access Database table in Asp.net




Please visit my new Web Site https://coderstechzone.com



In many forums i found that developers struggle "To connect with MS Access Database from Asp.net". Thats why in this post i will show you how one can access MS Access database from Asp.net ASPX page to bind GridView. To do that first open any MS Access Database & then create below table:


Fig: Entity

And ofcourse copy your MS Access mdb Database into your application root folder.

Ok, Now our MS Access Database Article table is ready. So add an aspx page in your asp.net project & then drag & drop a GridView within the page. Named it by gvArticle. Full HTML Markup Language is given below:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MSACCESSGV.aspx.cs" Inherits="MSACCESSGV" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test MS ACCESS DATABASE CONNECTION</title>
</head>

<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="gvArticle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Id" />
<asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Title" />
<asp:BoundField DataField="Published" HeaderText="Published" SortExpression="Visit" />
<asp:BoundField DataField="Modified" HeaderText="Modified" SortExpression="Modified" />
</Columns>
</asp:GridView>

</div>
</form>

</body>
</html>

Now you need to write code in server side to bind GridView gvArticle. First make connection string for your MS Access Database. And then read data from MS Access database. Complete server side code is given below:

using System;
using System.Data;
using System.Web.UI;
using System.Data.OleDb;

public partial class MSACCESSGV : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
string sFilePath = Server.MapPath("MSACCESS.mdb");
DataTable dt;
OleDbConnection Conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sFilePath + ";");

using (Conn)
{
Conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM ARTICLE", Conn);
OleDbDataAdapter oDA = new OleDbDataAdapter(cmd);
dt = new DataTable();
oDA.Fill(dt);
}

gvArticle.DataSource = dt;
gvArticle.DataBind();

}
}
}

Now run your page. And you will get an output like below:

Fig: Output

Hope now you can make connection with MS-Access Database & also can retrieve data from MS-Access from your asp.net application.
Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash