C#datagridview

来源:百度知道 编辑:UC知道 时间:2024/05/07 22:26:27
记得VB-SP6里有个msflexgrid控件,C#中用datagridview控件?如何实现其对应功能?如新增一列(其他几列数据经过一系列操作后的结果数据),如何新增一行,等等...越详细越好,请不要发msdn里的~wildbanana@163.com.学会定再加分
谁有复杂点的datdagridview(C#)实例?譬如连接数据库
a b c
1 2 3
2 3 4
3 4 5
如何显示出来
个位 十位 百位 合计
1 2 3 6
2 3 4 9
3 4 5 12

普通数据显示:
string s = "server=.;database=[你的数据库名];uid=sa"
SqlConnection con = new SqlConnection(s);

//我是使用的存储过程。就是存储过程名字为list
SqlDataAdapter sda = new SqlDataAdapter("list",con);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;

DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;

新建表:
DataTable dt = new DataTable("table1");
ds.Tables.Add(dt);

列:
DataColumn dc = new DataColumn("uid", typeof(Int32));
ds.Tables["table1"].Columns.Add(dc);
DataColumn dc2 = new DataColumn("username", typeof(string));
ds.Tables["table1"].Columns.Add(dc2);
dataGridView1.DataSource = ds.Tables["table1"].DefaultView;
行:
DataRow dr = ds.Tables["table1"].NewRow();