Results 1 to 6 of 6

Thread: C# and Database: How to Insert New record and save it

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    237

    Angry C# and Database: How to Insert New record and save it

    Dear All,

    I am a very much new to C#. Today I developed my first database application using c#.

    I am doing this to bind records:

    txtLastName.DataBindings.Add("text", myds, "pm.last_name");

    To move to next record(clicking next button):


    CurrencyManager cm = (CurrencyManager)this.BindingContext[myds, "pm"];
    if (cm.Position < cm.Count - 1)
    {
    cm.Position++;
    }

    else

    MessageBox.Show("End of records", "my application", MessageBoxButtons.OK, MessageBoxIcon.Information);


    and so on.

    I have completed the record navigation functionality(FirstRecord, LastRecord, Next, Previous).

    Problem:

    I don't know how can I insert a new record and save it.
    Please guide me in the above mentioned application.

    Also recommend a good tuturial+example on web.

    Thanks
    Last edited by engineer; Jun 2nd, 2006 at 05:20 PM.
    software engineer

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# and Database: How to Insert New record and save it

    There are numerous tutorial links in my signature. Some are ADO.NET specific and others have ADO.NET sections but much more besides.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    237

    Re: C# and Database: How to Insert New record and save it

    Ok. I am going to look into the links.
    Thanks.
    software engineer

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# and Database: How to Insert New record and save it

    Note that many of the tutorials are VB-based but the principles are exactly the same and there are links to code converters in my sig also, so you can convert the code examples if required. They are not 100% reliable but they do a good job in most cases and certainly enough to give you enough of an idea that you can fix any remaining issues by hand.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: C# and Database: How to Insert New record and save it

    What kind of database you're using? You could use a simple INSERT statement to insert into the table that you desire.

  6. #6
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: C# and Database: How to Insert New record and save it

    engineer:

    As JenniferBabe pointed out, we don't know what DMS you are using.

    Assuming you are using Access, you might find this example helpful.
    Last edited by AIS4U; Jun 22nd, 2006 at 11:12 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width