2强类型DataSet (2011-12-30 23:16:59)转载▼ 标签: 杂谈 分类: Asp.Net练习笔记 http://blog.sina.com.cn/s/blog_9d90c4140101214w.html

强类型DataSet

(2011-12-30 23:16:59)

标签:

杂谈

分类: Asp.Net练习笔记
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;
using DataSet.DataSet1TableAdapters;
using System.Diagnostics;
 
namespace DataSet
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            T_UsersTableAdapter adapter = new T_UsersTableAdapter();
            DataSet1.T_UsersDataTable data = adapter.GetData();
            for (int i = 0; i < data.Count; i++)
            {
                DataSet1.T_UsersRow userrow = data[i];
                if (userrow.IsUserNameNull() )
                {
                    MessageBox.Show("NULL");
                }
                else
                {
                    MessageBox.Show(userrow.UserName + userrow.UserPassWord);
                }
                
            }
 
            data[0].UserName = "luozixuan";
            adapter.Update(data);
            adapter.Insert("lineage", "lineage", 0);
            //表结构必须设置主键才可以使用update,delete
            for (int i = 0; i < data.Count; i++)
            {
                DataSet1.T_UsersRow userrow = data[i];
                MessageBox.Show(userrow.UserName + userrow.UserPassWord);
            }
        }
 
        private void Login_Click(object sender, EventArgs e)
        {
            T_UsersTableAdapter adapter = new T_UsersTableAdapter();
            DataSet.DataSet1.T_UsersDataTable datatable = adapter.GetDataByID(this.txtusername.Text);
            if (datatable.Count < 0)
            {
                MessageBox.Show("用户名错误");
            }
            else
            {
                DataSet.DataSet1.T_UsersRow datarow = datatable[0];
                if (datarow.ErrorTimes > 3)
                {
                    MessageBox.Show("登陆错误次数过多,账号被锁定,无法登陆!");
                    return;
                }
                if (datarow.UserPassWord == this.txtpassword.Text)
                {
                    MessageBox.Show("登陆成功!");
                    adapter.ReSetErrorTimes(datarow.Id);
                }
                else
                {
                    MessageBox.Show("密码错误");
                    adapter.AddErrorTimes(datarow.Id);
                }
            }
        }
        //强类型dataset批量更新数据时的连接处理方式
        private void button2_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            T_UsersTableAdapter adapter = new T_UsersTableAdapter();
            for (int i = 0; i < 1000; i++)
            {
                adapter.Insert(i.ToString(), i.ToString(), 0);
            }
                sw.Stop();
                MessageBox.Show(sw.Elapsed.ToString());
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            T_UsersTableAdapter adapter = new T_UsersTableAdapter();
            adapter.Connection.Open();
            for (int i = 0; i < 1000; i++)
            {
                adapter.Insert(i.ToString(), i.ToString(), 0);
            }
            adapter.Connection.Close();
            sw.Stop();
            MessageBox.Show(sw.Elapsed.ToString());
        }
    }
}
上一篇:微信小程序中无刷新修改


下一篇:MVC小系列(十六)【在控制器级别或具体Action级别上动态设定模板页(Layout)】