Saturday 20 December 2014

How To Insert DataGridView Multiple Row Values in Window Application using C#

Insert DataGridView Multiple Row Values  Using Window Application


DataGridView multiple Row  Values Insert into DataBase  using Window Application C#



                     DEMO




C# Coding

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 QueryWindows
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\users\drizzles\documents\visual studio 2012\Projects\QueryWindows\QueryWindows\Database1.mdf;Integrated Security=True");

            con.Open();

            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {

                string amounts = dataGridView1.Rows[i].Cells[0].Value.ToString();

                SqlCommand cmd = new SqlCommand("insert into register(amount)values('" + amounts + "')", con);

                cmd.ExecuteNonQuery();

                MessageBox.Show("Data Registered");

            }

        }
    }
}


First Create - New Window Form 









































0 comments:

Post a Comment