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
Solved

Inserting data with AccessDataSource control

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to refer to value 8 62
imap mails 1 25
jquery datatables, asp.net MVC 9 51
exporting html table data 4 26
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…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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