c# create dynamic datatable, datarow and insert data in .net



This is A C# Practice 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;

        namespace database
        {
            public partial class CreateTable : Form
            {
                public CreateTable()
                {
                    InitializeComponent();
                }

                private void button1_Click(object sender, EventArgs e)
                {
                    DataTable ss = new DataTable();
                    ss.Columns.Add("Id");
                    ss.Columns.Add("Names");
                    ss.Columns.Add("Address");
                    ss.Columns.Add("Project");
                    ss.Columns.Add("Qualification");

                    DataRow row = ss.NewRow();
                    row["Id"] = textBox1.Text;
                    row["Names"] = textBox2.Text;
                    row["Address"] = textBox3.Text;
                    row["Project"] = textBox4.Text;
                    row["Qualification"] = textBox5.Text;
                   
                    ss.Rows.Add(row);
                    foreach (DataRow Drow in ss.Rows)
                    {
                        int num = dataGridView1.Rows.Add();
                        dataGridView1.Rows[num].Cells[0].Value = Drow["id"].ToString();
                        dataGridView1.Rows[num].Cells[1].Value = Drow["Names"].ToString();
                        dataGridView1.Rows[num].Cells[2].Value = Drow["Address"].ToString();
                        dataGridView1.Rows[num].Cells[3].Value = Drow["Project"].ToString();
                        dataGridView1.Rows[num].Cells[4].Value = Drow["Qualification"].ToString();
                    }
                }
            }
        }

Video For Result:



Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Facebook Comment