+ Reply to Thread
Results 1 to 3 of 3

Thread: how to use insert command on c# form to access database

  1. #1
    Barn Regular arloguth is an unknown quantity at this point arloguth's Avatar
    Join Date
    Apr 2009
    Posts
    61
    Rep Power
    3

    how to use insert command on c# form to access database

    Hello,
    I have a C# form with two textboxes - bound to microsoft access database table with 2 fields.
    question: can I use C# form to enter records into access database- not just in database in bin folder?
    I know there is a insert command - but do not know how to apply it to a form with textboxes- I am hoping to create a form users can use once a week to enter one record- user open form -fills in two textboxes- and hits a command button to have it entered.
    can you help point me in right direction.

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    You can call an SQL command to insert records on a button click event, if that's what you mean? Something like:-
    Code:
    <asp:textbox id="txt1" runat="server />
    <asp:textbox id="txt2" runat="server" />
    <asp:button id="btn1" runat="server" onclick="btn1OnClick" />
    
    Code:
    public void btn1OnClick(Object s, EventArgs e)
    {
    string text1 = txt1.Text;
    string text2 = txt2.Text;
    string sql = "INSERT INTO tbl1(field1, field2) VALUES('" & text1 & "','" & text2 & "')";";
    //connect to db
    //execute sql command on db.
    }
    
    Obviously this is a very simplified version. You should check and validate values before inserting them into the db. You could also create a class that handles your db calls rather than doing it directly in the page.

    Hope that helps.

  3. #3
    Barn Regular arloguth is an unknown quantity at this point arloguth's Avatar
    Join Date
    Apr 2009
    Posts
    61
    Rep Power
    3

    thank you that helps

+ Reply to Thread

Similar Threads

  1. Open form automatically when opening database
    By Kristipy in forum Microsoft Access
    Replies: 2
    Last Post: September 2nd, 2009, 02:41 AM
  2. querying access database using php
    By tulz in forum PHP Development
    Replies: 4
    Last Post: October 27th, 2008, 03:37 PM
  3. Command Buttons Coloring
    By alansidman in forum Microsoft Access
    Replies: 5
    Last Post: May 15th, 2008, 04:57 PM
  4. How to Properly Configure Web Permissions on an Access Database
    By jmurrayhead in forum ASP Development
    Replies: 0
    Last Post: March 23rd, 2008, 11:44 AM
  5. Access Code/Database Samples
    By jmurrayhead in forum Microsoft Access
    Replies: 0
    Last Post: March 16th, 2008, 12:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO