Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem inserting into a databse

Status
Not open for further replies.

ola123

Technical User
Sep 16, 2005
52
JM
hey guys,

I'm having some difficulty getting the following to work properly. I'm trying to insert records into a database using the below below but I keep getting the error: "Syntax error in INSERT INTO statement." Why I really don't know.


your help would be greatly appreciated
I copied everything so u can get an idea of what i'm doing.

I'm inserting the records into a Microsoft access database file named ModDb more specifically into a table named record

here's the code

Code:
<%@ Page Language="VB" Debug="true"%>
<%@ Import Namespace=system.data.oledb %>

<script runat=server >

</script>

<html>
<head runat="server">
    <title>Modular Database</title>
</head>
<body >
    <form runat="server">
    <asp:AccessDataSource runat="server" ID="ADS" DataFile="ModDB.mdb"
        Selectcommand="SELECT * FROM Record"
        InsertCommand="INSERT INTO Record (Fname, Lname, Module, Age, Sex) VALUES
                     (@Fname, @Lname, @Module, @Age, @Sex)"
        >
               
    </asp:AccessDataSource>
        
    <asp:FormView runat="server" DataSourceID="ADS" ID="FV" DefaultMode="Insert" >
    <InsertItemTemplate>
                
        <table>
            <tr>
                <td>First Name:</td>    
                <td><asp:TextBox runat="server" ID="txtfname" Text='<%# bind("Fname") %>' /></td>
            </tr>
            
            <tr>
                <td>Last Name:</td>    
                <td><asp:TextBox runat="server" ID="txtlname" Text='<%# bind("Lname") %>'/></td>
            </tr>
            
            <tr>
                <td>Module</td>    
                <td><asp:TextBox runat="server" ID="txtmodule" Text='<%# bind("Module") %>' /></td>
            </tr>
            
            <tr>
                <td>Age</td>    
                <td><asp:TextBox runat="server" ID="txtage" Text='<%# bind("Age") %>' /></td>
            </tr>
            
            <tr>
                <td>Sex</td>    
                <td><asp:TextBox runat="server" ID="txtsex" Text='<%# bind("Sex") %>' /></td>
            </tr>
            
            <tr>
                <td><asp:Button runat="server" Text="submit" CommandName="Insert" /> </td>
            </tr>
        </table>
    
    </InsertItemTemplate>
    </asp:FormView>    
    </form>
   
</body>
</html>
 
Hey,

Have you checked the permissions on the .mdb file? Right click on it then Properties > Security. Make sure the ASP user has the proper permissions.

Brendan Murtagh - HostMySite.com
Technical Support Representative
bmurtagh@hostmysite.com
 
another problem: DataSource controls. you cannot debug or test them. the more markup you use the less control you have over the code.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
thanks for the input guys,
I'm kinda new to this, so i'm not quite clear on how to use less markups. I have written this code before & it's almost identical (wrote like 2yrs now) & it runs fine. Whats could what the problem with the above the permissions that BMurtagh are fine.
 
markup is the "code" that looks like HTML. the code behind (and other cs/vb files you create) are actual code. With this code you have greater control over how your application works. using drag/drop controls and IDE Wizards severely limits what you can produce.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Thanks jmeckley for the link, but here's the thing all that code is too much for me to understand much less to implement, regarding my code above i was going through a tutorial i dug up and i cant seem to find what the error is relating to, it might be elementary for you guys, but could you or anyone direct me toward the error could be or the simplest way to achieve inserting records in an access database,

thanks in advance.
 
all that code is too much for me to understand much less to implement
Are you refering to the FAQ link in my signature? That goes on every post, most people have questions about DB connections so I wrote a post about it.

Here is the thing about code. the more you write the more control you have. the more the IDE/wizards write, the less control you have. if the wizard driven "code" has a problem there is no easy way to debug or test. by that i mean automated unit tests and/or the ablitiy to step through the code with the debugger.
i was going through a tutorial i dug up and i cant seem to find what the error is relating to
how do you konw the tutorial is correct? I'm cautious of code that trusts drag/drop wizards over actual code. Not that the code itself is incorrect, but it speaks to the level of expertise the developer has in understand the language/framework.

Access is not a web friendly database either. Access is meant for single/few users local database. anything beyond that and you are better off using SqlExpress as the database. (Access or .net app as the front end)

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top