In RealTime most of the windows based applications are used dataGridview for Inserting,Deleting,for any Modifications we use dataGridview .So for that the data will send to dataGridview from TextBox. I gave some code for that shown below.
Code: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;
using System.Data.SqlClient;
namespace gridview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Column1");
dt.Columns.Add("Column2");
dt.Columns.Add("Column3");
dr = dt.NewRow();
dr["column1"] = textBox1.Text;
dr["column2"] = textBox2.Text;
dr["column3"] = textBox3.Text;
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
}
}
}
Code: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;
using System.Data.SqlClient;
namespace gridview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Column1");
dt.Columns.Add("Column2");
dt.Columns.Add("Column3");
dr = dt.NewRow();
dr["column1"] = textBox1.Text;
dr["column2"] = textBox2.Text;
dr["column3"] = textBox3.Text;
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
}
}
}
Below image shows form with TextBoxes and DataGridView.
Below image shows TextBoxes and Data inserted from TextBoxes to Datagridview.
I hope this code will help you.