杂谈二

 

6:用到图来建立数据关系 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient; 

namespace ADOtest1027

{

    public partial class FormEmployee : Form

    {

        public FormEmployee()

        {

            InitializeComponent();

        }  

        private void FormEmployee_Load(object sender, EventArgs e)

        {

            string ss = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks;Data Source=06E2CCCA8D3D463";

            string sql = @"select EmployeeID,Title,BirthDate,Gender,HireDate,ContactID from HumanResources.Employee";

 

            SqlDataAdapter da = new SqlDataAdapter(sql,ss );

            DataSet ds = new DataSet();

            da.Fill(ds,"Employee");

 

            dataGVtwoseven.DataSource = ds ;

            dataGVtwoseven.DataMember = "Employee";

        } 

        private void dataGVtwoseven_DoubleClick(object sender, EventArgs e)

        {

            //下面的一行中,Cells[5]的意思是选择

            //string sql = @"select EmployeeID,Title,BirthDate,Gender,HireDate,ContactID from HumanResources.Employee";

            //中所底六个位置的ContactID来作为主键,而来跳转到另一个页面

            string cid = dataGVtwoseven.SelectedRows[0].Cells[5].Value.ToString();

            contact_table contact = new contact_table();    //这里是以个自定义的.cs 代码是:如下面的

            contact.CID = Convert.ToInt32(cid );

            contact.ShowDialog();          

        }     

    }

}

***********************************************************************************************************************************************************

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient; 

namespace ADOtest1027

{

    public partial class contact_table : Form

    {

        private int cid;

        public int CID

        {

            set { cid = value; }

            get

            {

                return cid; 

            } 

        }

        public contact_table()

        {

            InitializeComponent();

        } 

        private void contact_table_Load(object sender, EventArgs e)

        {

            listViewContact.Columns.Add("ContactID",150, HorizontalAlignment.Center);

            listViewContact.Columns.Add("FirstName", 150, HorizontalAlignment.Center);

            listViewContact.Columns.Add("MiddleName", 150, HorizontalAlignment.Center);

            listViewContact.Columns.Add("LastName", 150, HorizontalAlignment.Center); 

            string ss = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks;Data Source=06E2CCCA8D3D463";

            string sql = @"select ContactID,FirstName,MiddleName,LastName from Person.Contact where ContactID="+CID+""; 

            SqlDataAdapter da = new SqlDataAdapter(sql, ss); 

            DSEmployeeME ds = new DSEmployeeME();

            da.Fill(ds, "ContactME"); 

            foreach (DSEmployeeME.ContactMERow drContact in ds.ContactME.Rows)

            {

                ListViewItem item = new ListViewItem();

                item.SubItems[0].Text = drContact.ContactID.ToString();

                item.SubItems.Add( drContact .FirstName);

                item.SubItems.Add(drContact .MiddleName );

                item.SubItems.Add(drContact .LastName );

                listViewContact .Items .Add (item );

            }

        }      

    }

}

 

7:查,排序,修改,显示

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

 

namespace ADO11_19Sort_AND_find

{

    public partial class Form1 : Form

    {

        private DataView dvperantment = new DataView();

        public Form1()

        {

            InitializeComponent();

        }

 

        private void btnload_Click(object sender, EventArgs e)

        {

            string constr = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks;Data Source=06E2CCCA8D3D463";

            string sqlselect = @"select * from HumanResources.Department";

            SqlDataAdapter da = new SqlDataAdapter(sqlselect, constr);

            DataSet ds = new DataSet();

            da.Fill(ds, "Department");

 

            dvperantment = ds.Tables["Department"].DefaultView;

            dgvDataView1119.DataSource = dvperantment;

        }

 

        private void btnSort_Click(object sender, EventArgs e)

        {

            dvperantment.Sort = "Name";

            dgvDataView1119.DataSource = dvperantment;

        }

 

        private void btnFilter_Click(object sender, EventArgs e)

        {

            dvperantment.RowFilter = "Name like'H%'";

            dgvDataView1119.DataSource = dvperantment;

        }

 

        private void btnFind_Click(object sender, EventArgs e)

        {

            dvperantment.Sort = "Name";

            DataRowView[] dvp = dvperantment.FindRows("Purchasing");

           // DataRowView[] dvp = dvperantment.FindRows("");

            foreach (DataRowView  dd in dvp )

            {

                string msg = string.Empty;

                msg ="Name:"+dd ["Name"].ToString ()+Environment .NewLine ;

                msg += "GroupName:" + dd["GroupName"].ToString() + "\n";

                msg += "ModifiedDate:" + dd["ModifiedDate"].ToString();

                MessageBox.Show(msg);

            }

            //MessageBox.Show();

        }

    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值