CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2011
    Posts
    9

    C# Form to edit a database.

    Hi!

    Ive been working on a project which allows forms to edit information for a database. For one form I must have:
    • An import button which should start an Open File dialog and using appropriate filtering allow the user to select the house details text file.
    • A button which saves the record to the data source (database).
    • A button which cancels the new record within the dataset.
    • A close button to return to the main menu.


    http://i276.photobucket.com/albums/k...Druid/menu.jpg

    Ive made out the form as seen above. I really don't know how to save the record or cancel a new record. I think Ive got the import function working. Could anyone hear give me a hint towards what could be used to fix this?

    The code im currently using is shown below:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace Assignment2_V1

    {
    public partial class Import : Form

    {
    public Import()

    {
    InitializeComponent();
    }

    private void houseBindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {

    this.Validate();
    this.houseBindingSource.EndEdit();
    this.tableAdapterManager.UpdateAll(this.estateAgentDataSet);
    }

    private void Import_Load(object sender, EventArgs e)
    {
    // TODO: This line of code loads data into the 'estateAgentDataSet.house' table. You can move, or remove it, as needed.
    this.houseTableAdapter.Fill(this.estateAgentDataSet.house);
    }

    private void btnClose_Click(object sender, EventArgs e)
    {
    this.Close();
    }

    private void garageToolStripButton_Click(object sender, EventArgs e)
    {

    try
    {
    this.houseTableAdapter.Garage(this.estateAgentDataSet.house);
    }

    catch (System.Exception ex)
    {
    System.Windows.Forms.MessageBox.Show(ex.Message);
    }

    }

    private void btnImport_Click(object sender, EventArgs e)
    {
    openFileDialog1.ShowDialog();
    }

    }
    }

  2. #2
    Join Date
    Apr 2011
    Posts
    9

    Re: C# Form to edit a database.

    I noticed the sticky that says I need to include my VS version.

    Im running Visual Studio 2008. I tihnk that means im using 3.5.net.

  3. #3
    Join Date
    Apr 2011
    Posts
    9

    Re: C# Form to edit a database.

    I can provide other information if required.

  4. #4
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Re: C# Form to edit a database.

    Quote Originally Posted by 27CDruid View Post
    Hi!
    I really don't know how to save the record or cancel a new record. I think Ive got the import function working. Could anyone hear give me a hint towards what could be used to fix this?
    when you say save to a data source (database) do you mean an actual database or something like a text file that is acting as a database?

    if you're talking about a text file you can use System.IO.Streamwriter to append text to an existing text file.

    and what is the exact purpose of the cancel button? it looks to me like a button that would clear the text boxes when clicked on it, in that case you'd want call the method clear() on them either one by one or put them in a collection class like <list> and then loop through them

    hope it helps.

    btw try to use tags when posting code

  5. #5
    Join Date
    Dec 2008
    Posts
    144

    Re: C# Form to edit a database.

    Specifically, use code tags around sections of code- it formats it so it's easy to read.

    If you're working with a SQL Server backend, then I highly reccomend LINQ to SQL- there are a ton of tutorials on Google for the details. It's very easy to use- much easier than ADO.NET (in my opinion).
    Code:
    if (Issue.Resolved)
    {
         ThreadTools.Click();
         MarkThreadResolved();
    }

Tags for this Thread

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

Featured