当前位置:编程学习 > C#/ASP.NET >>

c# 中datatable dataview List 在数据绑定时 比较下?

最好能结合代码例子给与总结···
补充:相互交流学习学习·~
追问:不要刷,拜托~~~
答案:dataTable 和 dataView 的绑定代码 没有大的区别;

dataTable 看成一个表的话,dataView 就是一张视图;

在视图里 可以排序,筛选,等操作数据比在DataTable 里面方便多.而且可以直接转换成DataTable;

List 集合类 一般做小型控件的绑定;datatable 和 dataview 做表格的绑定

至于代码 在 MSDN上有详细的介绍;

b [pin=

-p]p67ruiot-0r89u5648

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 DataGridViewDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string conn = "Data Source=B13;Initial Catalog=MySchool;User ID=student";
SqlConnection connectin = new SqlConnection(conn);
connectin.Open();
string sql = "select teacherid, loginid,易做图 from Teacher";

//把数据填充到DataSet中
DataSet ds = new DataSet();
SqlDataAdapter adpater = new SqlDataAdapter(sql,connectin);
adpater.Fill(ds,"Teacher");
//关联DataGridfView的数据源为前面得到的DataSet
dataGridView1.DataSource = ds.Tables["Teacher"];

//下面是像下拉框添加

comboBox1.DataSource = ds.Tables["Teacher"];
comboBox1.ValueMember = "teacherid";
comboBox1.DisplayMember = "loginid";

}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
}
}

我这正好有个dataGridView例子

上一个:网页学C#的方法及接下来应该学什么?
下一个:学C#的怎样才能快速过渡到JAVA中?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,