MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

ADO.NET

ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples

Examples

Same Table Structures, with Primary Key
Previous Home Next

In the strongly typed DataSet, Table1 can be used as a sample table that has primary keys defined on it.

  1. screate the column with primary key
    DataTable ftb = new DataTable();
    DataTable stb = new DataTable();
    ftb.Columns.Add("Eno", typeof(Int32));
    ftb.Columns.Add("Ename", typeof(String));
    ftb.PrimaryKey = new DataColumn[] { ftb.Columns["Eno"] };
    stb.Columns.Add("Eno", typeof(Int32));
    stb.Columns.Add("Ename", typeof(String));
    
  2. write the 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.OleDb;
    namespace WindowsFormsApplication15
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    DataTable ftb = new DataTable();
    DataTable stb = new DataTable();
    private void Form1_Load(object sender, EventArgs e)
    {
    ftb.Columns.Add("Eno", typeof(Int32));
    ftb.Columns.Add("Ename", typeof(String));
    ftb.PrimaryKey = new DataColumn[] { ftb.Columns["Eno"] };
    ftb.LoadDataRow(new object[] { "1", "Ashish" }, true);
    ftb.LoadDataRow(new object[] { "2", "KAMAL" }, true);
    stb.Columns.Add("Eno", typeof(Int32));
    stb.Columns.Add("Ename", typeof(String));
    stb.LoadDataRow(new object[] { "2", "Aditya" }, true);
    stb.LoadDataRow(new object[] { "3", "Anil" }, true);
    dataGridView1.DataSource = ftb;
    dataGridView2.DataSource = stb;  
    }
    private void button1_Click(object sender, EventArgs e)
    {
    ftb.Merge(stb);
    dataGridView1.DataSource=ftb;
    dataGridView2.Visible = false;  
    label1.Text = "After Merging";
    label2.Visible = false;
    }
    }
    }
    

     

    s
Previous Home Next