Solved

Creating a web form using asp.net

Posted on 2015-02-09
4
211 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
[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
  • 2
  • 2
4 Comments
 
LVL 15

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 15

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

632 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