Solved

Inserting data with AccessDataSource control

Posted on 2006-11-16
4
960 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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 …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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