Solved

Inserting data with AccessDataSource control

Posted on 2006-11-16
4
920 Views
Last Modified: 2008-01-09
I am trying to insert data from a form into an Access database.

I am using ASP.NET 2.0 and an AccessDataSource control as follows

    <asp:AccessDataSource ID="contactUsAccessDataSource" runat="server" DataFile="~/App_Data/Moesc8.MDB"
        InsertCommand="INSERT INTO [tblNameAddress] ([FirstName], [LastName], [TimeStamp2], [Address1], [City], [State], [ZipCode], [Email], [WorkPhone], [Fax], [Comments]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
        SelectCommand="SELECT * FROM [tblNameAddress]" >
         <InsertParameters>
            <asp:FormParameter Name="fname" FormField="firstNameTextBox" />
            <asp:FormParameter Name="lname" FormField="lastNameTextBox" />
            <asp:ControlParameter Name="time" Type="DateTime" ControlID="dateTimeLabel" />  
            <asp:FormParameter Name="address" FormField="addressTextBox" />
            <asp:FormParameter Name="city" FormField="cityTextBox" />
            <asp:FormParameter Name="state" FormField="stateDropDown" />
            <asp:FormParameter Name="zip" FormField="zipTextBox" />
            <asp:FormParameter Name="email" FormField="emailTextBox" />
            <asp:FormParameter Name="phone" FormField="phoneTextBox" />
            <asp:FormParameter Name="fax" FormField="faxTextBox" />
            <asp:FormParameter Name="comments" FormField="commentsTextBox" />
       
             
        </InsertParameters>
    </asp:AccessDataSource>

However, when I click on the submit button, I get the error message "System.Data.OleDb.OleDbException: Index or primary key cannot contain a Null value.".

This is the code for the method called when the submit button is clicked:


    protected void submitButton_Click(object sender, EventArgs e)
    {
       
        contactUsAccessDataSource.Insert();
         
    }

If anyone could help out I'd appreciate it.



0
Comment
Question by:FrankeButler
4 Comments
 
LVL 6

Expert Comment

by:riyazthad
ID: 17959285
Which is your primary key? Are you passing value this field?
0
 

Author Comment

by:FrankeButler
ID: 17987438
I found the problem. I thought that ID (an autonumber field in the Access db) was my primary key, but it turned out that first name, last name, and time were my primary keys. I edited the database to make the ID my primary key and now my code works!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18424090
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now