Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating a web form using asp.net

Posted on 2015-02-09
4
Medium Priority
?
217 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

722 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