Solved

Creating a web form using asp.net

Posted on 2015-02-09
4
190 Views
Last Modified: 2015-02-09
I am trying to create a web form which would add records to a Microsoft Access database (accbd format).
This will include several text boxes and drop down lists. But for the beginning I've created only two text boxes  - ID and Namef. Also, I' ve put a gridview item on the page so I can see changes in data as they occur.


After launching the page in a browser, filling the ID and Namef fields and pressing "submit" button I recieve and error message:

Screenshot---09-02-2015---12-31-03.png
My knowledge of asp.net and web programming in general is quite limited, so I based my form on code shown in that video:
https://www.youtube.com/watch?v=CKdQUgrL3Gg

My vb code is:

Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page

    

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myConn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim sqlString, ID, Namef As String

        ID = TxtID.Text
        Namef = txtNamef.Text

        myConn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=|DataDirectory|Database1.accdb;")

        myConn.Open()
        sqlString = "INSERT INTO Table1 (ID, Namef) VALUES ('" + ID + "', '" + Namef + "')"

        cmd = New OleDbCommand(sqlString, myConn)
        cmd.ExecuteNonQuery()
        myConn.Close()


    End Sub
End Class

Open in new window


I also attach an archive containing my project. The database is stored in App_Data folder.
Thanks in advance!
Attempt1.zip
0
Comment
Question by:German Mikulski
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Lokesh B R
ID: 40598157
Hi,

As i can see in your Table, you have already set the primary Key as ID.

Please change the query as below and try.

 sqlString = "INSERT INTO Table1 (Namef) VALUES ('" + Namef + "')"

Open in new window

0
 

Author Comment

by:German Mikulski
ID: 40598182
Hi,

Sorry, it didn't work, still getting the same mistake. Visual Studio points at  myConn.Open() line as at the one, where mistake occurs. Screenshots of table:
Screenshot---09-02-2015---12-53-57.pngScreenshot---09-02-2015---12-55-14.png
0
 
LVL 14

Accepted Solution

by:
Lokesh B R earned 500 total points
ID: 40598236
Hi,

When you use  Access 2007 or higher files using OLEDB connection in C# or VB.Net, you need to install this.

http://www.microsoft.com/en-in/download/confirmation.aspx?id=23734

Code as below.

 
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myConn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim sqlString, Namef As String

        Namef = txtNamef.Text
 myConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb;Persist Security Info=True;")

        myConn.Open()

        sqlString = "INSERT INTO Table1 (Namef) VALUES ('" + Namef + "')"

        cmd = New OleDbCommand(sqlString, myConn)
        cmd.ExecuteNonQuery()
        myConn.Close()


    End Sub
End Class

Open in new window

0
 

Author Closing Comment

by:German Mikulski
ID: 40598518
Thanks a lot! :)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create and populate iFrame onClick of a button? 1 77
Compare site how does it work 4 77
cookies analysis tools 2 91
contractual requirements for app hosting 3 103
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

776 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