我认为这应该是一个简单的修复,但两天后,我似乎无法找到解决方案。我有一个简单的ASP.NET VS Express 2012 for Web,我正在尝试在插入模式下使用FormView将记录插入到访问表中。
这是我的代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="insert.aspx.cs" Inherits="mapbook_admin_insert" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/mapbook/admin/mapbook.mdb"
InsertCommand="INSERT INTO tblMaps
(txtFileName, txtMapName, txtCity, txtAddress, txtMapPage, txtGrid, txtZip, txtGateCode
VALUES (?,?,?,?,?,?,?,?)">
</asp:AccessDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1" DefaultMode="Insert" Width="452px">
<InsertItemTemplate>
PDF File Name:
<asp:TextBox ID="txtFileNameTextBox" runat="server" Text='<%# Bind("txtFileName") %>' />
<br />
Map Name:
<asp:TextBox ID="txtMapNameTextBox" runat="server" Text='<%# Bind("txtMapName") %>' />
<br />
City:
<asp:TextBox ID="txtCityTextBox" runat="server" Text='<%# Bind("txtCity") %>' />
<br />
Address:
<asp:TextBox ID="txtAddressTextBox" runat="server" Text='<%# Bind("txtAddress") %>' />
<br />
Map Page:
<asp:TextBox ID="txtMapPageTextBox" runat="server" Text='<%# Bind("txtMapPage") %>' />
<br />
Grid:
<asp:TextBox ID="txtGridTextBox" runat="server" Text='<%# Bind("txtGrid") %>' />
<br />
Zip:
<asp:TextBox ID="txtZipTextBox" runat="server" Text='<%# Bind("txtZip") %>' />
<br />
Gate Code:
<asp:TextBox ID="txtGateCodeTextBox" runat="server" Text='<%# Bind("txtGateCode") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
</asp:Content>
我得到的错误是“System.Data.OleDb.OleDbException:INSERT INTO语句中的语法错误。”我正在插入Access数据库。
先谢谢大家。
答案 0 :(得分:0)
感谢Richard Deeming,他在INSERT命令中注意到我遗失了')'。它现在正在运作。