locked
How to update,with DataGridView. RRS feed

  • Question

  • How UPDATE DATABASE with DataGridView FormA(sifpolj) FormB(izmena)

    FORM A(sifpolj)

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace EvID
    { 
      
        public partial class sifpolj : Form
        {
    
            public static string imepr;
            
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                if (m.Msg == WM_NCHITTEST)
                    m.Result = (IntPtr)(HT_CAPTION);
            }
    
            private const int WM_NCHITTEST = 0x84;
            private const int HT_CLIENT = 0x1;
            private const int HT_CAPTION = 0x2;
            
    
            public sifpolj()
            {
                InitializeComponent();
                MaximizeBox = false;
    
            
             }
            
    
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'polopDataSet1.sifpoljop' table. You can move, or remove it, as needed.
                this.sifpoljopTableAdapter.Fill(this.polopDataSet1.sifpoljop);
                
            }
          
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                usifpolj unos = new usifpolj();
                unos.ShowDialog();
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                this.sifpoljopTableAdapter.Fill(this.polopDataSet1.sifpoljop);
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("Da li zelite da izbrisete kontakt iz sifarnika", "Brisanje...", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    
                    foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
                    {
                        sifpoljopBindingSource.RemoveAt(item.Index);
                    }
                    sifpoljopTableAdapter.Update(polopDataSet1);
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                
                EvID.izmena frm = new izmena();
                //Load data from DATAGRIDVIEW To Form2
               
                    frm.textBox1.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    frm.textprezime.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    frm.textBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
                    frm.textBox4.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    frm.textBox5.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
                    frm.textBox6.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
                    frm.textBox7.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
                    frm.textBox8.Text = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
                    frm.checkBox1.Text = this.dataGridView1.CurrentRow.Cells[8].Value.ToString();
                    frm.textBox9.Text = this.dataGridView1.CurrentRow.Cells[9].Value.ToString();
                    frm.textBox10.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    frm.textBox11.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    //Change txt Form
                    frm.Text = "Uspesno izmenjeno";
                    frm.label13.Text = "ID : " + frm.textBox1.Text;
                    frm.textBox1.Enabled = false;
                    frm.ShowDialog();
               
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void button6_Click(object sender, EventArgs e)
            {
    
                WindowState = FormWindowState.Minimized;
            }
    
            private void label1_Click(object sender, EventArgs e)
            {
    
            }
           
        }
    }

    FORM B(izmena)

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    
    namespace EvID
    {   
        public partial class izmena : Form
        {
            
            public izmena()
            {
                InitializeComponent();
                
                
            }
    
           
             private void button2_Click(object sender, EventArgs e)
            {
            
                
            }
    
    
            private void izmena_Load(object sender, EventArgs e)
            {
                
            }
    
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                
            }
            
           
    
            private void button5_Click(object sender, EventArgs e)
            {
                this.Close();
            }
            
        }
    }

    Please HELP me.

    Thank you.

    Image : http://prntscr.com/b9k6lp

    http://prntscr.com/b9k5l3



                 






    Saturday, May 28, 2016 4:05 PM

Answers

All replies