Monday, May 9, 2016

Fetch Data from SQL database in Disconnected Environment

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 WindowsFormsApplication16
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SqlDataAdapter da;
        DataSet ds;
 
 
        private void Form1_Load(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select * from emp", "data source=MKS-PC\\SQLEXPRESS;Initial Catalog=master;integrated security=true");
            ds = new DataSet();
            da.Fill(ds);
 
        }
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = ds.Tables[0].Rows[0][0].ToString();
            textBox2.Text = ds.Tables[0].Rows[0][1].ToString();
            textBox3.Text = ds.Tables[0].Rows[0][2].ToString();
 
        }
    }

}

Output :

No comments:

Post a Comment