Monday 14 April 2014

Edit_Update a data from database with button in window form


                                                                                                                                         Previous
                                                                                                                                              Next

Here i will explain Edit_Update data from database in window form. Before this i explain that How to insert data into database using code.

Step(1) : Registration form with update button
Drag and down a button from tool box and give it name as Update.

Step(2) : Code
Double click on update button and write code, database is same as shown you in tutorial 6.



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

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Update_Click(object sender, EventArgs e)
        {
               SqlConnection con = new SqlConnection(str);
                String str = "server=MUNESH-PC;database=windowapp;UID=sa;password=123";
                String query = "update set Name = '" + this.name_txt.Text + "', Surname= '" + this.surname_txt.Text +"',Age= '" + this.Age_txt.Text+ "' where ID= '" + this.id_txt.Text + "' ";
         
              SqlCommand cmd = new sqComamnd(query,con);
                SqlDataReader dbr;
                       
               try
              {
               con.open();
               dbr = cmd.ExecuteReader();
                MessageBox.Show("Updated data");
              while(dbr.read())
             {
                 
              }
            }
            catch (Exception es)
            {
                MessageBox.Show(es.Message);

            }
        }
    }
} 

Step(3) : Output
Run your programme and click on update button.

                                                                                                                                         Previous
                                                                                                                                              Next

No comments:

Post a Comment

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...