Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2005, 05:05 AM
Registered User
Join Date: Feb 2005
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old April 11th, 2005, 09:12 PM
Registered User
Join Date: Apr 2005
Location: Cordova, TN, USA.
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.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 06:56 AM.

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