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例子