ݺߣ

ݺߣShare a Scribd company logo
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string cstr = "Server=.sqlexpress; Database=DBHocSinh; Integrated
security=true";
            SqlConnection con = new SqlConnection(cstr);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM HocSinh",
con);
            DataTable hs = new DataTable();
            da.Fill(hs);
            dgvDSHS.DataSource= hs;


              SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM Lop", con);
              DataTable lop = new DataTable();
              da1.Fill(lop);
              //Dien ra combobox lop
              cboLop.DataSource = lop;
              cboLop.DisplayMember = lop.Columns[1].ColumnName;
              cboLop.ValueMember = "MaLop";

              con.Close();

         }

        private void dgvDSHS_CellContentClick(object sender,
DataGridViewCellEventArgs e)
        {
            DoDuLieuRaLuoi(e.RowIndex);
        }

         private void DoDuLieuRaLuoi(int dong)
         {
             txtMaHS.Text = dgvDSHS.Rows[dong].Cells[0].Value.ToString();
             txtTen.Text = dgvDSHS.Rows[dong].Cells[1].Value.ToString();
             dtpNgSinh.Text = dgvDSHS.Rows[dong].Cells[2].Value.ToString();
             txtDiaChi.Text = dgvDSHS.Rows[dong].Cells[3].Value.ToString();
             txtDTB.Text = dgvDSHS.Rows[dong].Cells[4].Value.ToString();
             cboLop.Text = dgvDSHS.Rows[dong].Cells[4].Value.ToString();
         }
    }
}

More Related Content

New text document

  • 1. 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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string cstr = "Server=.sqlexpress; Database=DBHocSinh; Integrated security=true"; SqlConnection con = new SqlConnection(cstr); con.Open(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM HocSinh", con); DataTable hs = new DataTable(); da.Fill(hs); dgvDSHS.DataSource= hs; SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM Lop", con); DataTable lop = new DataTable(); da1.Fill(lop); //Dien ra combobox lop cboLop.DataSource = lop; cboLop.DisplayMember = lop.Columns[1].ColumnName; cboLop.ValueMember = "MaLop"; con.Close(); } private void dgvDSHS_CellContentClick(object sender, DataGridViewCellEventArgs e) { DoDuLieuRaLuoi(e.RowIndex); } private void DoDuLieuRaLuoi(int dong) { txtMaHS.Text = dgvDSHS.Rows[dong].Cells[0].Value.ToString(); txtTen.Text = dgvDSHS.Rows[dong].Cells[1].Value.ToString(); dtpNgSinh.Text = dgvDSHS.Rows[dong].Cells[2].Value.ToString(); txtDiaChi.Text = dgvDSHS.Rows[dong].Cells[3].Value.ToString(); txtDTB.Text = dgvDSHS.Rows[dong].Cells[4].Value.ToString(); cboLop.Text = dgvDSHS.Rows[dong].Cells[4].Value.ToString(); } } }