Solved

Inserting data with AccessDataSource control

Posted on 2006-11-16
4
952 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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