none
access database edit from visual c# RRS feed

  • Question

  •  

    I am not very experienced about programming and i have visual c# 2005 express edition. I need a c# project relates with access databases. i know how to bind the access database but i need two buttons to edit database from c# project . Save and Cancel. Save button should save the changes in the database if there is a change. if there is no  change in database a messeage box pop up and alert. When you click cancel button a message box should say "do you want to save te changes?" with Yes and No buttons below .Yes button same code with save button and no button should cancel all changes in database and returns the original database before edition.
    Sunday, April 27, 2008 3:02 PM

All replies

  •  egemon wrote:

     

    I am not very experienced about programming and i have visual c# 2005 express edition. I need a c# project relates with access databases. i know how to bind the access database but i need two buttons to edit database from c# project . Save and Cancel. Save button should save the changes in the database if there is a change. if there is no  change in database a messeage box pop up and alert. When you click cancel button a message box should say "do you want to save te changes?" with Yes and No buttons below .Yes button same code with save button and no button should cancel all changes in database and returns the original database before edition.

     

    Open up your Visual Studio or (Visual C#), click New tab, Projects, select Windows Forms from the menu, you will get a start up form like a simple bland rectangle.

     

    You can keep the original form or expand it to make to custom shaped. Then you drag a button from the toolBox and drop it on the form. You can right click on the button and say copy, then right click on the form and say: paste. That will give you a second button on the same form.

     

    At this point you may want to rename the buttons for further use, otherwise while working with the code you will find the names confusing.

     

    Click on one of the buttons, not hard, just touch it and highlight it. Find Properties on the right, find object name which is Button1 and remane it something like: butCancel or butDownload or butQuit. My prefernce is pushStop, pushCancel, etc.

     

    After you renamed both buttons double click on one of them. This will generate a delegate for you

     

    pushCancel_Click ( object sender, EventArgs e )

    {

     

    }

     

    It will be in your code in the file Form1.cs

     

    It is up to you to fill it with connection strings, etc.

    Sunday, April 27, 2008 5:53 PM
  • Thanks , i applied and finished the configuration of the buttons - and i think its the easy part of that . Now on i just need the the code that saves the changes to database when i click that button. Which that you show on reply

     

    pushCancel_Click ( object sender, EventArgs e )

    {

    this.save database (this code i need);

    }

    Sunday, April 27, 2008 7:29 PM
  • here u go mite

    pushCancel_Click ( object sender, EventArgs e )

    {

     if(MessageBox.show("Are you sure you want to cancle", "Cancel DB CHanges",MessageBox.Button.OK and Cancel)==DialogResult.OK)

    {

    // Then Cancel it

    }

    else

    {

    // Save it ( Use ds.GetCHanges if u r using a DataGrid and then call da.Update(ds,ds.Table[0]);

    }

    }


    for more info

    http://blog.paranoidferret.com/index.php/2007/09/05/c-tutorial-binding-a-datagridview-to-a-database/



    Peace

    Kartik



    Sunday, April 27, 2008 8:29 PM
  •  egemon wrote:

    Thanks , i applied and finished the configuration of the buttons - and i think its the easy part of that . Now on i just need the the code that saves the changes to database when i click that button. Which that you show on reply

     

    pushCancel_Click ( object sender, EventArgs e )

    {

    this.save database (this code i need);

    }

     

    That pushCancel was just an example! For the save button logically you should use pushSave convention. You need something that will help you to identify your delegate in a massive block of code which your Windows.Forms application may well become in a month or so. You need to use mnemonics for that.

     

    I guess to answer your question as to how to save the changes to your DB one has to know what code you use to make the changes. I kind of forgot from the OP, was it a DataAdapter?

     

    If you haven't provided clear details you should do it now.

    Monday, April 28, 2008 2:20 AM