Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 9th, 2005, 05:05 AM
Registered User
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting into access db using VWD.


I just joined here and also just started using asp.net 2.0.

So my question is how can i INSERT a new value to an access database. in my case a new category to a "cats" table. as i understand first i need to create a form with a label, a textbox and a submit button. then i need to create an AccessDataSource, and last code a btn_click event. so this is where i stoped, i dont how how to do so.

Here is a sample picture and code.

Acess DB:


    <form id="form1" runat="server">
        <asp:Label ID="lblInsertCat" Runat="server" Text="Enter category name:"></asp:Label>
        <asp:TextBox ID="txtInsertCat" Runat="server"></asp:TextBox>
        <asp:Button ID="btnInsertCat" Runat="server" Text="Insert" OnClick="btnInsertCat_Click" />
        <br />
        <asp:AccessDataSource ID="AccessDataSource1" Runat="server" DataFile="~/Data/data.mdb"
            DeleteCommand="DELETE FROM [Cats] WHERE [CatID] = ?" InsertCommand="INSERT INTO [Cats] ([CatID], [CatName]) VALUES (?, ?)"
            SelectCommand="SELECT * FROM [Cats]" UpdateCommand="UPDATE [Cats] SET [CatName] = ? WHERE [CatID] = ?">
                <asp:Parameter Type="Int32" Name="CatID"></asp:Parameter>
                <asp:Parameter Type="String" Name="CatName"></asp:Parameter>
                <asp:Parameter Type="Int32" Name="CatID"></asp:Parameter>
                <asp:Parameter Type="Int32" Name="CatID"></asp:Parameter>
                <asp:Parameter Type="String" Name="CatName"></asp:Parameter>



Partial Class Default_aspx

    Sub btnInsertCat_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
End Class

Old April 11th, 2005, 09:12 PM
Registered User
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to IceBreakerG Send a message via MSN to IceBreakerG Send a message via Yahoo to IceBreakerG

I know this is a few months old, but if you're still interested, try this code in your btnInsertCat_Click event:

Private Sub btnInsertCat_Click(ByVal sender As Object, ByVal e As System.EventArgs)
     'Add a new category into the table
     Dim cnCat As New OleDbConnection(<Connection String Here>)
     Dim daCat As New OleDbDataAdapter
     Dim cmCat As New OleDbCommand
     Dim sSQL As String

     sSQL = "INSERT INTO INSERT INTO [Cats] ([CatID], [CatName]) VALUES (?, ?)"
     cmCat.CommandText = sSQL
     cmCat.CommandType = CommandType.Text
     cmCat.Connection = cnCat
     daCat.Command = cmCat
     If cnCat.State = ConnectionState.Open() Then cnCat.Close()
End Sub

If any thinks there are any errors in this code, please correct it, I hope this helps.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening DB from VWD - per p. 683-684 JimBloomfield BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 June 16th, 2006 11:49 AM
Problem with inserting data into an Access DB donrafeal ASP.NET 2.0 Basics 0 January 6th, 2006 05:34 PM
inserting yes/no value into Access DB using ASP pablohoney Classic ASP Basics 1 September 20th, 2005 12:00 AM
Inserting a value containing ' into a db jfrizelle Classic ASP Databases 2 November 10th, 2004 08:55 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.