DataSet部分示例
来源:互联网 发布:淘宝卖干果要什么手续 编辑:程序博客网 时间:2024/04/30 03:45
1)创建一个WinForm应用程序
2)在窗体上添加一个DataGridView(dataGridView1)
3)在窗体上添加三个文本框(textBox1,textBox2,textBox3)
4)添加四个Button(button1,button2[标题为delete],button3[标题为remove],button3)
5)添加一个图片框(pictureBox1)
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;
namespace DataSetSample3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet ds = new DataSet("学生数据集");
DataTable table = new DataTable("学生");
private void Form1_Load(object sender, EventArgs e)
{
DataColumn dc = table.Columns.Add("序号", typeof(int));
dc.AutoIncrement = true;
dc.AutoIncrementSeed = 1;
dc.AutoIncrementStep = 1;
dc.ReadOnly = true;
table.Columns.Add("学号", typeof(string));
table.Columns["学号"].Unique = true;
table.Columns.Add("姓名",
System.Type.GetType("System.String"));
table.Columns.Add("年龄",typeof(int));
table.Columns["年龄"].DefaultValue = 20;
table.Columns.Add("年龄2", typeof(int));
table.Columns["年龄2"].Expression = "年龄*2";
table.Columns["年龄2"].ReadOnly = true;
table.Columns.Add("照片", typeof(byte[]));
//table.Columns.Add("照片",
// System.Type.GetType("System.Byte[]"));
table.PrimaryKey = new DataColumn[]{
table.Columns["学号"]};
ds.Tables.Add(table);
dataGridView1.DataSource = table;
}
//双击可以编辑照片
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
if (openDlg.ShowDialog() == DialogResult.OK)
pictureBox1.Image = Image.FromFile(openDlg.FileName);
}
private void button1_Click(object sender, EventArgs e)
{
DataRow row = table.NewRow();
row["学号"] = textBox1.Text;
row["姓名"] = textBox2.Text;
row["年龄"] = int.Parse(textBox3.Text);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
pictureBox1.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
row["照片"] = ms.ToArray();
table.Rows.Add(row);
}
private void button2_Click(object sender, EventArgs e)
{
table.Rows[0].Delete();
}
private void button3_Click(object sender, EventArgs e)
{
table.Rows.Remove(table.Rows[0]);
}
private void button4_Click(object sender, EventArgs e)
{
DataRow[] rows = table.Select("年龄>=20", "年龄 ASC");
for (int i = 0; i < rows.Length; i++)
rows[i]["年龄"] = 0;
}
}
}
- DataSet部分示例
- DataSet应用示例
- c# 中DataSet示例
- LINQ to DataSet 示例
- 判断dataset是否为空 &dataset取值示例
- html部分示例
- Android部分控件示例汇总
- 简易计算器代码示例【部分】
- ATG执行sql部分示例
- 6.Utm示例-公共部分
- DataSet
- DataSet
- DataSet
- DataSet
- DataSet
- dataset
- DataSet
- DataSet
- AutoIt V3.2.13.7 可模拟PC鼠标移动和窗口来实现自动化任务
- OpenLayers项目分析——(十)控件
- 耳朵贴地
- 多核并行计算时代的来临
- OpenLayers项目分析——(十一)事件机制分析
- DataSet部分示例
- 7步打造最佳简历
- 初冬游瘦西湖
- 为经济危机“未雨绸缪
- OpenLayers分析——(十二)体系结构
- [双语阅读]妮可•基德曼:是否继续演艺事业?这是个问题
- 一种正规的性能调优方法:基于等待的调优
- [英语阅读]经济危机致韩国避孕套销量上升
- Designing and Building Enterprise DMZs [ILLUSTRATED]