Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating a web form using asp.net

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Suggested Courses

963 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